forum

Home / DeveloperSection / Forums / Index was out of range in grid row command

Index was out of range in grid row command

Anonymous User212501-Sep-2014

I'd like to reach gridView a cell's value.But it gives the error is 'Index was out of range. Must be non-negative and less than the size of the collection. grid row command'

Can somebody help me?

 <asp:GridView ID="grdList" runat="server" AutoGenerateColumns="False"  GridLines="None"

            PageSize="5" AllowPaging="True" OnPageIndexChanging="Grd_Allergys_PageIndexChanging"

            OnRowCommand="grdList_RowCommand" OnRowDeleting="grdList_RowDeleting" OnRowEditing="grdList_RowEditing">

            <Columns>

                <asp:BoundField DataField="LangId" HeaderText="LangId" />

                <asp:BoundField DataField="LangName" HeaderText="LangName" />

                <asp:TemplateField HeaderText="Edit">

                    <ItemTemplate>

                        <asp:ImageButton ID="imgBtnEdit" runat="server" CommandName="Edit" CommandArgument='<%#Eval("LangId") %>'

                            ImageUrl="~/Image/edit.jpg" />

                    </ItemTemplate>

                </asp:TemplateField>

                <asp:TemplateField HeaderText="Delete">

                    <ItemTemplate>

                        <asp:ImageButton ID="imgBtnDelete" runat="server" CommandName="Delete" CommandArgument='<%#Eval("LangId")%>'

                            ImageUrl="~/Image/delete_icon.gif" OnClientClick="return confirm('Do you want to continue ?')" />

                    </ItemTemplate>

                </asp:TemplateField>

            </Columns>

            <PagerSettings Mode="Numeric" />

        </asp:GridView>

 protected void grdList_RowCommand(object sender, GridViewCommandEventArgs e)

 {

        DBDataContext dc = new DBDataContext();

        if (e.CommandName == "Edit")

        {                      

           int rowIndex = int.Parse(e.CommandArgument.ToString());

           string LangName = grdList.DataKeys[rowIndex]["LangName"].ToString();                             

        }                   

 }


Updated on 01-Sep-2014
I am a content writter !

Can you answer this question?


Answer

1 Answers

Liked By