protected void gvRaceList_RowCommand(object sender, GridViewCommandEventArgs e) { int rowIndex = Convert.ToInt32(e.CommandArgument); // row contains current Clicked Gridview Row DataKey dkRace = gvRaceList.DataKeys[rowIndex]; // set our dkRace datakey to the rowindex datakey value, remember to set GV datakey properties on aspx page to correct value! int RaceID = Convert.ToInt32(dkRace.Values["RaceID"]); if (e.CommandName == "DeleteJob") { dataaccess.daSQLapp objRace = new dataaccess.daSQLapp(); objRace.DelRaceInfo(RaceID, ConnectionString); PopulateGridView(); } else if (e.CommandName == "EditDetails") { int RowIndex = Convert.ToInt32(e.CommandArgument); } }