Last post Jun 09, 2017 06:42 AM by kaushalparik27
Jun 05, 2017 07:35 AM|Queries|LINK
I have a gridview which has 2 header rows as below
| Name | Subject1 | Subject2 |
| |Theory | Viva |Theory | Viva |
| John | | | | |
| Ann | | | | |
When user clicks on a cell I want to know whether he has clicked on
cell corresponding to
Subject1 Theory or Subject1 Viva or
Subject2 Theory or Subject2 Viva.
protected override void Render(HtmlTextWriter writer)
foreach (GridViewRow row in gvStudent.Rows)
string StudentID = gvStudent.DataKeys[row.RowIndex].Value.ToString();
//I can identify which row (Student name) clicked.
foreach (TableCell cell in row.Cells)
if (cell is DataControlFieldCell)
int ind = row.Cells.GetCellIndex(cell);
string SubjectSelected= gvStudent.HeaderRow.Cells[ind].Text;
//This returns if Subject1 was selected or Subject2 was selected. (header row 1)
But how to find if cell corresponding to column Theory or Viva was clicked (Header row 2)
Is there something like accessing header row by index if there are more than one headers for the grid??
something like string TheoryOrVivaSelected= gvStudent.HeaderRow.Cells[ind].Text; is available ???
Jun 09, 2017 06:42 AM|kaushalparik27|LINK
TheoryOrVivaSelected= gvStudent.HeaderRow.Cells[ind].Text; is available ???
gvStudent.HeaderRow will always return single GridViewRow; it does not return multiple rows since there will be always single header by default. So, if you have index of cell which is clicked in a variable named as ind then you can get header as:
But, if you have some custom implementation with functionality of multiple Headers in GridView then I suggest to make use of GridView1.HeaderRow.Controls OR GridView1.HeaderRow.Cells[ind].Controls. You may get some hint.