I would like to make my Gridview header dynamic i.e databound from
database..
I want my users to be able to change the headers on the fly..
Can you clarify what you mean, please...
Are you saying that you want your users to be able to choose which
columns are displayed, or just to be able to change the text displayed
at the top of each column...?
If the latter, what happens if e.g. your GridView has four columns and
they specify the same header for all of them...?
The header colmuns would be fixed so lets say 4 and thats it.
Just to be able to change the text displayed on top of each column.
<asp:GridView ID="MyGridView" runat="server"
OnRowDataBound="MyGridView_RowDataBound" AutoGenerateColumns="False">
protected void MyGridView_RowDataBound(object sender,
GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Header)
{
e.Row.Cells[0].Text = "First";
e.Row.Cells[1].Text = "Second";
e.Row.Cells[2].Text = "Third";
e.Row.Cells[3].Text = "Fourth";
}
}