I have an ASP.NET c# GridView which has columns that look like this:
| Foo | Bar | Total1 | Total2 | Total3 |
Is it possible to create a header on rows that looks like this?
| General | Totals |
| | A | B | C |
| Foo | Bar | 1 | 2 | 3 |
I have tried with RowCreated method, but I'm stopped to :
| General | Totals |
| Foo | Bar | 1 | 2 | 3 |
My code below.
Can you help me?
Thank you in advance for any help, really appreciated.
protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Header)
{
GridView ProductGrid = (GridView)sender;
GridViewRow HeaderRow = new GridViewRow(0, 0,
DataControlRowType.Header, DataControlRowState.Insert);
TableCell HeaderCell = new TableCell();
HeaderCell.Text = "General";
HeaderCell.HorizontalAlign = HorizontalAlign.Center;
HeaderCell.ColumnSpan = 2;
HeaderCell.CssClass = "HeaderStyle";
HeaderRow.Cells.Add(HeaderCell);
ProductGrid.Controls[0].Controls.AddAt(0, HeaderRow);
HeaderCell = new TableCell();
HeaderCell.Text = "Totals";
HeaderCell.HorizontalAlign = HorizontalAlign.Center;
HeaderCell.ColumnSpan = 3;
HeaderCell.CssClass = "HeaderStyle";
HeaderRow.Cells.Add(HeaderCell);
}
}
This is how you can do it. This snippet add all 3 header rows programatically. But you could also use the normal GridView header as the 3rd row. So for my example the gridview should look like this and has 5 columns
And then the RowCreated method