Brijesh Patel
Brijesh Patel

Reputation: 2958

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

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?

Upvotes: 3

Views: 8356

Answers (3)

Saurabh Singh
Saurabh Singh

Reputation: 63

Dim tr As New HtmlTableRow
tr.Cells.Add(New HtmlTableCell("th"))
yourtable.Rows.Add(tr)

Upvotes: 1

elsni
elsni

Reputation: 2053

Table t = new Table();
TableHeaderRow th = new TableHeaderRow();
th.Controls.Add(new LiteralControl("test"));
t.Controls.Add(th);
containerControlForTheTable.Controls.Add(t);

Upvotes: 3

Ropstah
Ropstah

Reputation: 17804

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

Upvotes: 5

Related Questions