Get Row Index on Asp.net Rowcommand event

Shahin picture Shahin · Jun 28, 2011 · Viewed 111.2k times · Source

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.

Answer

rahularyansharma picture rahularyansharma · Jun 28, 2011

this is answer for your question.

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

int RowIndex = gvr.RowIndex;