【发布时间】:2011-05-06 05:03:09
【问题描述】:
另见相关问题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> 来生成表格,但我很想看看这是否可以完成。
【问题讨论】: