You must be aware of this, that
RowCommand
event is raised when a button is clicked in the
GridView
control. Which enables you to provide an
event-handling method that performs a custom routine whenever this event occurs.
Refer more detailed description here:
GridView.RowCommand Event[
^]
This is how you can get the index of GridView row using
RowCommand
:
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Show")
{
int index = Convert.ToInt32(e.CommandArgument);
int documentID = Convert.ToInt32(GridView1.DataKeys[index].Value);
}
}
Ref.:Get RowIndex In GridView RowCommand Event Using DataKey[^]