另请参阅相关问题我们可以在同一个 https://stackoverflow.com/questions/3076708/can-we-have-multiple-tbody-in-same-table
假设我想使用 asp:table 生成下表:
<table>
<thead>
...stuff...
</thead>
<tbody class="odd">
<th scope="tbody">CUSTOMER 1</th>
<tr><td>#1</td><td>January</td></tr>
<tr><td>#2</td><td>April</td></tr>
<tr><td>#3</td><td>March</td></tr>
</tbody>
<tbody class="even">
<th scope="tbody">CUSTOMER 2</th>
<tr><td>#1</td><td>January</td></tr>
<tr><td>#2</td><td>April</td></tr>
<tr><td>#3</td><td>March</td></tr>
</tbody>
<tbody class="odd">
<th scope="tbody">CUSTOMER 3</th>
<tr><td>#1</td><td>January</td></tr>
<tr><td>#2</td><td>April</td></tr>
<tr><td>#3</td><td>March</td></tr>
</tbody>
</table>
我可以建造这些吗<tbody>
/ <tr>
以编程方式元素?
我尝试做类似的事情:
var x = new HtmlGenericControl("tbody");
x.Attributes["class"] = jobNum % 2 == 0 ? "even" : "odd";
TableRow xinfoRow = buildXInfoRow(job); x.Controls.Add(xinfoRow);
TableRow xdescriptionRow = buildXDescriptionRow(job); x.Controls.Add(xdescriptionRow);
myTable.Controls.Add(x);
但这只是给了我错误'Table' cannot have children of type 'HtmlGenericControl'
.
我可以找到TableRow、TableCell、TableHeaderRow、TableHeaderCell 等类,但我似乎找不到TableBody 或TableHeader。我可以在页眉、正文或页脚中放置行:
descriptionRow.TableSection = TableRowSection.TableBody;
...但我似乎无法将行分成多个不同的<tbody>
元素。我几乎放弃并转而使用<asp:ListView>
生成表格,但我有兴趣看看是否可以做到这一点。