Search code examples
c#asp.netgridviewrowcommand

Get Row Index on Asp.net Rowcommand event


I have an asp.net GridView:

<asp:TemplateField HeaderText="View Faktor" ShowHeader="False" Visible="True">
    <ItemTemplate>
        <asp:ImageButton ID="imgBtn1" CssClass="SelectRow" runat="server" CausesValidation="false"
            CommandArgument='<%#(eval("mprID")) %>' CommandName="ViewFactors" ImageUrl="~/tadarokat/Images/factor.png"
            Text="" />
    </ItemTemplate>
</asp:TemplateField>

How Can I get rowIndex on row command event?

I want to highlight (select) target row when RowCommand fires.


Solution

  • this is answer for your question.

    GridViewRow gvr = (GridViewRow)((ImageButton)e.CommandSource).NamingContainer;
    
    int RowIndex = gvr.RowIndex;