views:

396

answers:

2

I've a gridview in my web form and I'm using a the following code in my web form's 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 can I get the current cell's header text.

+1  A: 

gvList.Rows[0] should be your header row. You should be able to get

gvList.Rows[0].Cells[i]

That's just to get the cell itself. You'll need to go into the cell and get Controls[0] and cast it to its proper type then get the Text property.

Joel Etherton
+1  A: 

I solved it using:

  string headerRowText = gvList.HeaderRow.Cells[i].Text;
hotcoder