GridView Header Text in asp.net
64,991
Solution 1
It should be gridview1.Columns[ColumnIndex].HeaderText = "Header text";
Solution 2
For this, in the RowDataBound event of the gridview control you need to write as like follows:
if (e.Row.RowType == DataControlRowType.Header)
{
e.Row.Cells[0].Text = "column 1";
e.Row.Cells[1].Text = "column 2";
.....
}
Author by
Abbas
Updated on November 05, 2020Comments
-
Abbas over 3 years
I want to change the header text of the gridview using Design from
<TemplateField HeaderText="">
.I created a variable in code behind which is public and set the value in that variable and then I tried to call that variable over here as below:
<TemplateField HeaderText = '<%= VariableCallHere %>'
But while running the page, I got <%= VariableCallHere %> as a header text.
Even I tried changing using
gridView1.HeaderRow.Cells[0].Text = "text Here"
(This Throws object reference error)Any one have any suggestions how this could be achieved?
-
Coops almost 10 yearsI wanted to set the header text based upon logic for the dataRows (after the Header row) and this did nothing but
gridView1.HeaderRow.Cells[ColumnIndex].Text
did work. I don't understand, but useful for anyone else struggling with this.