Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Row index of LinkButton in GridView

Tags:

c#

.net

asp.net

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

like image 636
Vinod Avatar asked Jan 02 '12 10:01

Vinod


People also ask

What is RowCommand event in GridView?

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.

What is e RowIndex in C#?

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.


1 Answers

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..

like image 134
Jignesh Rajput Avatar answered Oct 04 '22 06:10

Jignesh Rajput