我有一个 GridView,我想从中获取列标题的文本。
for (int j = 0; j < grdToDisplay.HeaderRow.Cells.Count; j++)
{
string s = grdToDisplay.HeaderRow.Cells[j].Text.ToString(); //Returns ""
s = grdToDisplay.HeaderRow.Cells[j].Text; //Returns ""
s = grdToDisplay.Rows[0].Cells[j].Text; //Returns text from first row of results not the header
// s = grdToDisplay.Columns[j].HeaderText.ToString(); // does not work as column count is 0
}
GridView 内容是在运行时根据用户查询生成的。标题可以点击排序。
如何循环 GridView 并列出列标题文本?