簡體   English   中英

我該如何重復 <tr> 在C#做一個清單?

[英]How can I repeat a <tr> in c# to make a list?

我想用

這是我在listOfPeople.aspx上的代碼:

<table id="listOfPeople" runat="server">
<tr id="rowOfPerson" runat="server">
 <td id="person" runat="server">name of a person</td>
</tr>
</table>

我想重復通過C#列出人員列表:

<table>
<tr>
 <td>Charles Bell</td>
</tr>
<tr>
 <td>Jason Mc Allister</td>
</tr>
<tr>
 <td>Mathew Anderson</td>
</tr>
</table>

我可以在listOfPerson.aspx.cs上看到“ rowOfPerson”,但我不知道如何創建新行。 謝謝。

刪除aspx中的表格html。 在aspx.cs中,編寫整個表(包括所需的所有行),以便根據數據源的不同來動態呈現該表。 這只是許多方法中的一種,但是我相信這是您實現這一目標的最簡單,最快的方法。

有多種方法...

將此html放入中繼器控件,並將datasaource分配給它

<tr id="rowOfPerson" runat="server">
 <td id="person" runat="server">name of a person</td>
</tr>

使用其他方法,例如使用具有runat服務器屬性的表添加...在代碼中循環遍歷數據,並為該表添加tr作為您的數據...

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM