I am using Link button as Template Field in GridView.
Now i want to display the row index of the Linkbutton clicked.
Please suggest me a solution Thanks in advance
The RowCommand event is raised when a button is clicked in the GridView control. This enables you to provide an event-handling method that performs a custom routine whenever this event occurs.
As the object suggests (GridViewUpdateEventArgs) 'e' stands for the events relating to the update of a grid view. You can get similar method signatures that relate to other events such as deletions etc. The 'RowIndex' relates to the index of the row on which this event was fired.
suppose in Item Template this is ur link button
<ItemTemplate>
<asp:LinkButton ID="lnkapprove" Font-Underline="true" runat="server" Text="Approve" OnClick="lnkapprove_Click"></asp:LinkButton>
</ItemTemplate>
in Code Behind:
protected void lnkapprove_Click(object sender, EventArgs e)
{
LinkButton btn = (LinkButton)sender;
GridViewRow row = (GridViewRow)btn.NamingContainer;
int i = Convert.ToInt32(row.RowIndex);
}
you can get row.RowIndex like this..
Hope this helps..
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With