Search This Blog

Wednesday, September 1, 2010

Show a Main Header in Gridview along with the GridView Column Headers

You have to manually add a row to the table generated by the GridView follows.
<asp:GridView ID="GridView1" runat="server" AllowPaging="true" PageSize="10"
OnPreRender="GridView1_PreRender"/>

protected void GridView1_PreRender(object sender, EventArgs e)
{

GridViewRow gv = new GridViewRow(0, 0, DataControlRowType.Header, DataControlRowState.Normal);
TableCell tbCell = new TableCell();
tbCell.ColumnSpan = 3;
tbCell.Text = "GridView Header";
tbCell.Attributes.Add("style", "text-align:center");
gv.Cells.Add(tbCell);
GridView1.Controls[0].Controls.AddAt(0, gv);

}

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.