Get Gridview Cell Header Text

I have a gridview in my web form and I am using the following code in my web form. Save Button:

foreach (GridViewRow row in gvList.Rows) if (row.RowType == DataControlRowType.DataRow) { for (int i = 0; i < row.Cells.Count; i++) { string headerRowText = ???; 

How to get the current text of the cell header.

+6
header gridview
source share
4 answers

I solved this using:

  string headerRowText = gvList.HeaderRow.Cells[i].Text; 
+21
source share

gvList.Rows [0] should be your title bar. You should be able to get

 gvList.Rows[0].Cells[i] 

It is just to get a cage. You will need to enter the cell and get Controls [0] and apply it to the appropriate type, and then get the Text property.

+3
source share
 string headerRowText = gvList.HeaderRow.Cells[i].Text; 

returned an empty string for me that the work was:

 GridView1.Columns[i].HeaderText 
+3
source share

Set property GridView UseAccessibleHeaderText=true

Then, when encoding the code, to use the j-th column:

 GridView1.HeaderRow.Cells[0].Text 
+1
source share

All Articles