asp.netgridviewheadertext

What is difference between GridView1.HeaderRow.Cells[4].Text and GridView1.Columns[4].HeaderText?


I placed a Placeholder server control on aspx page.

create a Grid-view instance in code behind.

set data-source to it

Now i want to change it header text.so first i tried as given below:

GridView1.Columns[4].HeaderText = "ABC";

header text not changed.

then i tried with:

GridView1.HeaderRow.Cells[4].Text="ABC";

header text changed now.

Added GridView control to PlaceHolder server control:

plhGridView.Controls.Add(GridView1);

I want to know that why header text not changed when i tried first time?

Thanks


Solution

  • May be you are not binding columns with your Rows in your former code

    GridView1.Columns[4].HeaderText = "ABC";
    

    You can do this from the former code using RowDataBound handler for details use the following link:

    ASP.NET: When and how to dynamically change Gridview's headerText's in code behind?