I am using C#'s HtmlTextWriter to create a HTML table.
When I loop trough creating my table header it creats it in this format
<tr><th>colname</th><th>colname</th><th>colname</th><th>colname</th></tr>
I want the <tr>
to say <thead>
and the <th>
to say <td>
.
How do I program HtmlTextWriter to change the tag values?
Here's my loop for creating the header.
public void BuildHTMLTable(DataTable dt)
{
StringWriter sw = new StringWriter();
HtmlTextWriter w = new HtmlTextWriter(sw);
Table tbl = new Table();
tbl.ID = "example";
tbl.CssClass = "display";
tbl.CellSpacing = 0;
TableHeaderRow thr = new TableHeaderRow();
foreach (DataColumn col in dt.Columns)
{
TableCell th = new TableCell();
th.Text = col.Caption;
thr.Controls.Add(th);
}
tbl.Controls.Add(thr);
foreach (DataRow row in dt.Rows)
{
TableRow tr = new TableRow();
foreach (var value in row.ItemArray)
{
TableCell td = new TableCell();
td.Text = value.ToString();
tr.Controls.Add(td);
}
tbl.Controls.Add(tr);
}
TableFooterRow tfr = new TableFooterRow();
foreach (DataColumn col in dt.Columns)
{
TableCell th = new TableCell();
th.Text = col.Caption;
tfr.Controls.Add(th);
}
tbl.Controls.Add(tfr);
tbl.RenderControl(w);
tableString = sw.ToString();
}