开发者

Get Header Text of Gridview Cell

I've a g开发者_StackOverflow社区ridview 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.


I solved it using:

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


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

returned empty string for me, what did work was:

GridView1.Columns[i].HeaderText


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.


Set GridView property UseAccessibleHeaderText=true

Then, on code-behind, to get j-th column use:

GridView1.HeaderRow.Cells[0].Text
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜