[英]Adding rows dynamically in a table in C# while populating data from sqlserver
我正在使用下拉列表框選定的值從sqlserver檢索數據,並將其存儲在arraylist中。 現在的問題是如何重新排列arraylist值並在表中顯示。
如下使用
ArrayList myArrayList = new ArrayList();
//Fill ArrayList values from the SQL Server
myArrayList.Add("Hello");
myArrayList.Add("World");
Table table = new Table();
foreach (var item in myArrayList)
{
TableRow tr = new TableRow();
TableCell tc = new TableCell();
//Add Arraylist item into TableCell to display it
tc.Text = item.ToString();
tr.Cells.Add(tc);
table.Rows.Add(tr);
}
如果您使用的是asp.net mvc,則可以使用以下代碼:
<table>
@foreach (var item in List) {
<tr>
<td>
item.somethingA
</td>
<td>
item.somethingB
</td>
</tr>
}
</table>
等創建表
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.