Set the CommandName and CommandArgument fields in the GridView then you can access those values in the code behind.
So say you have an image button in every row and when a user selects the button you want to access the command name and parameter for that row.
<asp:GridView ID="gvwRecords" runat="server" DataKeyNames="ID" DataSourceID="objRecords" OnRowCommand="gvwRecords_RowCommand">
<Columns>
<asp:TemplateField HeaderImageUrl="~/Images/Approve_Header_Dark.gif">
<ItemTemplate>
<asp:ImageButton runat="server" ID="btnApprove" %>'
CausesValidation="false" AlternateText="Approve record" ImageUrl="~/Images/Unapproved.gif"
CommandName="Approve" CommandArgument='<%# Eval("ID") %>' />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
In the code behind:
protected void gvwRecords_RowCommand(object sender, GridViewCommandEventArgs e)
{
int recordID = int.Parse(e.CommandArgument.ToString());
if (recordID > 0)
{
switch (e.CommandName.ToLower())
{
case "sort":
break;
case "approve":
Record.ApproveRecord(recordID);
gvwRecords.DataBind();
break;
...
}
}
}