How do I get Gridview to render THEAD? How do I get Gridview to render THEAD? asp.net asp.net

How do I get Gridview to render THEAD?


This should do it:

gv.HeaderRow.TableSection = TableRowSection.TableHeader;


I use this in OnRowDataBound event:

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.