3

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

Sukhjeevan
  • 3,074
  • 9
  • 46
  • 89

2 Answers2

0

If you want to try first time code. You have to set GridView1.AllowSorting="true"; and write OnSorting event for GridView.

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

If what you want is:

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

This will keep the sort.

Josua Marcel C
  • 3,122
  • 6
  • 45
  • 87
0

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?

Community
  • 1
  • 1