Pages

21 Aug 2013

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


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.


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

    }

No comments:

Post a Comment