Get Header Text of Gridview Cell

依然范特西╮ 提交于 2019-12-22 04:55:10

问题


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:


I solved it using:

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



回答2:


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.




回答3:


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

returned empty string for me, what did work was:

GridView1.Columns[i].HeaderText



回答4:


Set GridView property UseAccessibleHeaderText=true

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

GridView1.HeaderRow.Cells[0].Text


来源:https://stackoverflow.com/questions/2091202/get-header-text-of-gridview-cell

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!