This should do it:
gv.HeaderRow.TableSection = TableRowSection.TableHeader;
I use this in OnRowDataBound event:
OnRowDataBound
protected void GridViewResults_OnRowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.Header) { e.Row.TableSection = TableRowSection.TableHeader; }}
The code in the answer needs to go on Page_Load or GridView_PreRender. I put it in a method that was called after Page_Load and got a NullReferenceException.
Page_Load
GridView_PreRender
NullReferenceException