0

I have a gridview bound to a datatable and want the gridview to render the first row as a header row (th not td) along with the normal column namnes being rendered as a header row. Currently I am trying to this here:

protected void SampleGrid_DataBound(object sender, EventArgs e)
{
    GridView grid = sender as GridView;
    grid.Rows[1].RowType = DataControlRowType.Header;
}

This isn't working. I am open to any solution for this problem including manipulating the DataTable, the grid view, or the underlying HTML table through javascript. I am a C# coder and VB.net looks like gibberish to me so I would appreciate code in C#.

Thank you for your time.

cuongle
  • 74,024
  • 28
  • 151
  • 206
Tarynn
  • 469
  • 1
  • 5
  • 14
  • The answers to this question may help you http://stackoverflow.com/questions/314736/asp-net-gridview-second-header-row-to-span-main-header-row?rq=1 – Coral Doe Sep 10 '12 at 08:21

1 Answers1

2

The GridView control doesn't allow a second header by default.

Any means to add a second header would involve some hack.

Here are two blogs that show you how to do it:

Real World GridView: Two Headed

Dynamic Multiple Row Column Grid Header

Another hack is setting the HeaderText of some column to a value like </th></tr><tr><th> And split the rows yourself.

nunespascal
  • 17,584
  • 2
  • 43
  • 46
  • Thank you, I had read those articles and hadn't thought they applied because I was doing something slightly different. You answer made me look at them again and think a bit more out of the box. I appreciate your time, – Tarynn Sep 15 '12 at 23:00