How to insert <th> tag in the table in asp.net in code behind file?

Brijesh Patel picture Brijesh Patel · Apr 18, 2012 · Viewed 7.5k times · Source

I am adding table in code behind file. and i want to add tag in that.

<table id="tbl" runat="server">
   <tr>
        <th>test</th>
       <td>
       </td>
   </tr>
</table>

I dont know how to add through code.

So can any one tell me how to add tag?

Answer

Ropstah picture Ropstah · Apr 18, 2012
HtmlTable t = tbl; //just to make it clear your table is an HtmlTable
tbl.Rows[0].Cells.Add(new HtmlTableCell("th")); //adds an emtpy cell to the first row with th tagname