views:

55

answers:

1

is it possible inside the gridview events for commands to find a cell by datafield name or headertext name when using boundcolumns?

+1  A: 

you can find a column in GridView.Columns and then use its index to find a desired cell. Something like in this example:

protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
  var myColumn = GridView1.Columns.Cast<DataControlField>().First(c => c.HeaderText == "MyColumn");
  var row = GridView1.Rows[int.Parse(e.CommandArgument.ToString())];
  var cell = row.Cells[GridView1.Columns.IndexOf(myColumn)];
}
dh