First you must set the type of the header of the first line when it is created:
protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e) { if (e.Row.RowIndex == 0) { e.Row.RowType = DataControlRowType.Header; } }
Now you can do it:
GridView1.DataSource = dt; GridView1.DataBind(); GridView1.HeaderRow.TableSection = TableRowSection.TableHeader;
source share