asp.net c#gridview-如何知道单击了哪个单元格

asp.net c#gridview-如何知道单击了哪个单元格,c#,asp.net,gridview,C#,Asp.net,Gridview,我有一个gridview,它有两个标题行,如下所示 | Name | Subject1 | Subject2 | | |Theory | Viva |Theory | Viva | |-------|-------|-------|-------|------| | John | | | | | | Ann | | | | | 当用户点击一个单元格时,我想知道他是

我有一个gridview,它有两个标题行,如下所示

| Name  |   Subject1    |  Subject2    |
|       |Theory | Viva  |Theory | Viva |
|-------|-------|-------|-------|------|
| John  |       |       |       |      |
| Ann   |       |       |       |      |
当用户点击一个单元格时,我想知道他是点击了theory还是viva专栏

通过使用gvStudent.DataKeys[row.RowIndex].Value.ToString();我能够检索已设置为gridview数据键的学生ID。因此能够识别他单击的行

使用gvStudent.HeaderRow.Cells[index].Text;我能确定他点击了哪个主题

但如何知道他是否点击了理论或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; 
            } 
         }
      }
}

如何处理单击事件?如何将列拆分为Theory和Viva,按照相同的方法查找受保护的覆盖无效呈现(HtmlTextWriter writer){int studentid=gvStudent.DataKeys[row.RowIndex].Value.ToString();foreach(gvStudent.Rows中的GridViewRow){foreach(row.Cells中的TableCell单元格){if(单元格为DataControlFieldCell){string subjectselected=gvStudent.HeaderRow.Cells[ind].Text;}请在帖子中编辑相关代码,不要使用注释,只需使用CellClick事件。DataGridViewCellEventArgs将包含您需要的内容。(e.ColumnIndex)