There are 726 articles on Google when you search "gridview thead". Most of them, and certainly all the first ones, talk about not being able to render thead, tbody and tfoot elements for NET 2.0 table based controls. But it's not so!

Each table row has a property called TableSection. If you set it to TableRowSection.TableHeader, TableBody or TableFooter, the specific tags will be created. Let me show a quick example of creating a THEAD element in a gridview:
gridView.HeaderRow.TableSection=TableRowSection.TableHeader;

And that's it. This kind of behaviour works for the Table WebControl and everything that derives from it or uses it to render itself.
However, the rendering of these elements inside the Table control is done simply with writer.RenderBeginTag(HtmlTextWriterTag.Thead), which gives no one the ability to change from .NET code the attributes of those sections. You can't have it all! You can use CSS, though. ex:
.tableClass thead {
position:relative;
}

Comments

Siderite

<p>Who uses a DataGrid anymore? Isn't that .Net 1.1? The post does say NET2.0 table based controls.</p>

Siderite

Anonymous

<p>Hey that code doesn't work for datagrid. <br><br>although<br>Gatagrid.UseAccessibleHeader = True<br>renders th tags for header columns <br>unfortunetly not thead tag</p>

Anonymous

Siderite

Who uses a DataGrid anymore? Isn&#39;t that .Net 1.1? The post does say NET2.0 table based controls.

Siderite

Anonymous

Hey that code doesn&#39;t work for datagrid. <br><br>although<br>Gatagrid.UseAccessibleHeader = True<br>renders th tags for header columns <br>unfortunetly not thead tag

Anonymous

Anonymous

<p>Solution is described at my blog at <a href="http://nmarian.blogspot.com/2007/08/aspnet-datagrid-rendered-with-thead.html" rel="nofollow noopener" title="http://nmarian.blogspot.com/2007/08/aspnet-datagrid-rendered-with-thead.html">http://nmarian.blogspot.com...</a></p>

Anonymous

Anonymous

Solution is described at my blog at http://nmarian.blogspot.com/2007/08/aspnet-datagrid-rendered-with-thead.html

Anonymous

Siderite

<p>foreach (GridViewRow row in grid.Rows) row.TableSection=TableRowSection.TableBody;</p>

Siderite

Siderite

foreach (GridViewRow row in grid.Rows) row.TableSection=TableRowSection.TableBody;

Siderite

Anonymous

<p>Siderite, thanks for the good work - it was very helpful. however, i'm having issues setting the TableSection for the Rows (to generate TBODY. Can you please post the syntax for that?</p>

Anonymous

Anonymous

Siderite, thanks for the good work - it was very helpful. however, i&#39;m having issues setting the TableSection for the Rows (to generate TBODY. Can you please post the syntax for that?

Anonymous

Anonymous

<p>Thank you. This was exactly what I was looking for!</p>

Anonymous

Anonymous

Thank you. This was exactly what I was looking for!

Anonymous

Siderite

<p>well, yes, best option is at prerender, I think.</p>

Siderite

wechel

<p>Make sure you set this after data has been bound.<br><br>i.e.<br>void grid_DataBound(object sender, EventArgs e)<br> {<br> grid.HeaderRow.TableSection = TableRowSection.TableHeader;<br> }</p>

wechel

Siderite

well, yes, best option is at prerender, I think.

Siderite

wechel

Make sure you set this after data has been bound.<br><br>i.e.<br>void grid_DataBound(object sender, EventArgs e)<br> {<br> grid.HeaderRow.TableSection = TableRowSection.TableHeader;<br> }

wechel

Post a comment