views:

1232

answers:

2

How do I get the GridView control to render the <thead> <tbody> tags? I know .UseAccessibleHeaders makes it put <th> instead of <td>, but I cant get the <thead> to appear.

+11  A: 

This should do it...

gv.HeaderRow.TableSection = TableRowSection.TableHeader;
Phil Jenkins
I just found that and was about to answer myself, thanks anyway, spot on :)
Andrew Bullock
The `HeaderRow` property will be `null` until the `GridView` has been data bound, so make sure to wait until databinding has occurred before running the above line of code.
bdukes
+1  A: 

The code in the answer needs to go in Page_Load or GridView_PreRender. I put it in a method that was called after Page_Load and got a NullReferenceException.

You can also put in `DataBound` event. `grid.DataBound += (s, e) => { grid.HeaderRow.TableSection = TableRowSection.TableHeader; };`
BrunoLM