我有一个gridview,它有2个标题行,如下所示
| Name | Subject1 | Subject2 |
| |Theory | Viva |Theory | Viva |
|-------|-------|-------|-------|------|
| John | | | | |
| Ann | | | | |
当用户点击一个单元格时,我想知道他是否点击了理论或viva专栏。
使用gvStudent.DataKeys [row.RowIndex] .Value.ToString();我能够检索我已设置为gridview的datakey的学生ID。因此能够识别他点击的行。
使用gvStudent.HeaderRow.Cells [index] .Text;我能够识别他点击的主题。
但如何知道他是否点击过Theory或Viva专栏。 任何帮助将不胜感激。
动态代码
protected override void Render(HtmlTextWriter writer)
{
int studentid=gvStudent.DataKeys[row.RowIndex].Value.ToString();
foreach (GridViewRow row in gvStudent.Rows)
{
foreach (TableCell cell in row.Cells)
{
if (cell is DataControlFieldCell)
{
string subjectselected= gvStudent.HeaderRow.Cells[ind].Text;
}
}
}
}