Q:

ASP.Net: Getting DataKey from GridView on Edit and Delete

I am using a GridView control which is databound to a List of objects returned from a utility method. The GridView control has one of the columns set as its DataKey. When a row is Selected, it fires the Selected event handler and I can use myGridView.SelectedDataKey.Value to get the value of the DataKey column for the selected row.
However, the event handler for when a row is Edited or Deleted does not seem to have a mechanism to get the DataKey value for the row in question. The event arg parameter for these event handlers contains the index of the row in the GridView but I'm specifically after the DataKey value.
Re-obtaining the List of objects via the utility method along with the index obtained from the event arg parameter is not an option because the List of objects may have changed.
Can anyone tell me how I can do this?
TIA

A:

 protected void gridQuestion_RowDeleting(object sender, GridViewDeleteEventArgs e)
 {
     int id = (int)grdQuestions.DataKeys[e.RowIndex].Value;      
 }

