-1

I specifically need thead tags in my program. When I use System.Web.UI.WebControls; it outputs header rows as <tr> tags instead of <thead> tags. Is there a way to change this so that it says <thead>?

 StringWriter sw = new StringWriter();
 HtmlTextWriter w = new HtmlTextWriter(sw);

 Table tbl = new Table();

 TableHeaderRow thr = new TableHeaderRow();
 foreach (DataColumn col in dt.Columns)
 {
     TableCell th = new TableCell();
     th.Text = col.Caption;
     th.ID = "cellSize";
     thr.Controls.Add(th);
 }
 tbl.Controls.Add(thr);

 tbl.RenderControl(w);
 tableString = sw.ToString();

This outputs a row like <tr><td></td></tr>

Frantumn
  • 1,725
  • 7
  • 36
  • 61
  • Do you mean it puts `` tags instead of `` tags? – mason Jul 29 '14 at 19:26
  • You can go lower level and create your HTML via StringBuilder. This way you will have exact control over the tags. – Yuriy Galanter Jul 29 '14 at 19:27
  • tr tags should be one level lower than thead tags. thead and tbody tags should envelop tr tags. – itsme86 Jul 29 '14 at 19:28
  • @mason yes, it puts TR tags. and I need THEAD tags – Frantumn Jul 29 '14 at 19:28
  • You still need tr tags. The output you're showing is valid. I think what you mean is you want th tags instead of td tags. It should look like – itsme86 Jul 29 '14 at 19:30
  • 1
    I think you're confused over the difference between ``, `` and `` tags. `` is completely different, as the children of `` should be `` tags. The children of `` tags should be `` (regular cell) or `` (header cell) tags. That said, if you need fine grained control over the generated HTML, then don't use controls. Write HTML yourself, or find a library that's meant for it. – mason Jul 29 '14 at 19:31

1 Answers1

0

You should be using TableHeaderCell instead of TableCell in your TableHeaderRow. This will emit <th> tags intead of <td> tags in your header.

You can find information on TableHeaderCell here.

itsme86
  • 19,266
  • 4
  • 41
  • 57
  • Thank you. I did try this. The reason I need it to use thead tags is that I'm using jquery datatables and that plugin requires those tags. – Frantumn Jul 29 '14 at 19:44