April 25, 2011

Group header row in GridView in ASP.Net

protected void gvBDAC_RowDataBound(object sender, GridViewRowEventArgs e)
{
GridViewRow gvr = e.Row;

if(gvr.RowType == DataControlRowType.Header)
{
GridViewRow row = new GridViewRow(0,0,DataControlRowType.Header,DataControlRowState.Normal);

TableCell cell = new TableCell();
cell.ColumnSpan = 1;
cell.HorizontalAlign = HorizontalAlign.Center;
cell.Text = "SRNo";
row.Cells.Add(cell);

cell = new TableCell();
cell.ColumnSpan = 2;
cell.HorizontalAlign = HorizontalAlign.Center;
cell.Text = "complaints on previous day";
row.Cells.Add(cell);

cell = new TableCell();
cell.ColumnSpan = 2;
cell.HorizontalAlign = HorizontalAlign.Center;
cell.Text = "Pending complaints for the day";
row.Cells.Add(cell);

cell = new TableCell();
cell.ColumnSpan = 1;
cell.HorizontalAlign = HorizontalAlign.Center;
cell.Text = "Fault Count";
row.Cells.Add(cell);


Table tbl = (e.Row.Parent as Table) ;
tbl.Rows.AddAt(0, row);


}
}

No comments:

Post a Comment