假设我有一个DataTable[]
数组。在每个DataTable中最多有5行。每行有5列。我需要在一个5 x 5的html表中显示DataTable的内容,这样在dataTable的一个单元格和一个html表格的单元格之间存在一对一的关系(即td)。
任何人都可以给我一些关于如何实现这一目标的代码吗?它需要循环遍历DataTable数组的长度。因此,如果有3个DataTable,则需要创建3个html表。
我的数据表的示例
Row 1 : Colors, Sizes, Length
Row 2 : Blue , L , 23
Row 3 : Green , M , 24
Row 4 : Red , S , 25
Row 5 : Yellow, , 26
答案 0 :(得分:1)
StringBuilder html = new StringBuilder();
foreach(DataTable aTable in tableList)
{
html.Append("<table>");
foreach(DataRow row in aTable.rows)
{
html.Append("<tr>");
foreach(string cell in row.Items)
{
html.Append("<td>");
if (cell == null)
html.Append(" ");
else
html.Append(cell);
html.Append("</td>");
}
html.Append("</tr>");
}
html.Append("</table>");
}