See also the related question can we have multiple <tbody> in same <table>?
Say I want to generate the following table using 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>
Can I build these <tbody>
/ <tr>
elements programmatically?
I tried doing something like:
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);
But this just gives me the error 'Table' cannot have children of type 'HtmlGenericControl'
.
I can find a TableRow, TableCell, TableHeaderRow, TableHeaderCell, etc. classes, but I can't seem to find TableBody or TableHeader. I can place rows within the header, body or footer:
descriptionRow.TableSection = TableRowSection.TableBody;
...but I can't seem to divide the rows into multiple different <tbody>
elements. I've pretty much given up and gone to using an <asp:ListView>
to generate the table, but I'm interested to see if this can be done.