Hi all
i have this grid view as below:
<asp:GridView ID="GVAssetList" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:BoundField DataField="Asset_ID" HeaderText="Asset ID" />
<asp:BoundField DataField="Asset_Name" HeaderText="Asset Name" />
<asp:BoundField DataField="Asset_SN" HeaderText="Asset SN" />
<asp:BoundField DataField="Make" HeaderText="Asset Make" />
<asp:BoundField DataField="Model" HeaderText="Asset Model" />
<asp:BoundField DataField="Asset_Status" HeaderText="Asset Status" />
<asp:BoundField DataField="Emp_Name" HeaderText="Assinged to" />
<asp:TemplateField>
<ItemTemplate>
<asp:Button runat="server" ID="btnSelect" Text="Select" OnClick="btnSelect_Click" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
and the code behind the page :
<asp:GridView ID="GVAssetList" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:BoundField DataField="Asset_ID" HeaderText="Asset ID" />
<asp:BoundField DataField="Asset_Name" HeaderText="Asset Name" />
<asp:BoundField DataField="Asset_SN" HeaderText="Asset SN" />
<asp:BoundField DataField="Make" HeaderText="Asset Make" />
<asp:BoundField DataField="Model" HeaderText="Asset Model" />
<asp:BoundField DataField="Asset_Status" HeaderText="Asset Status" />
<asp:BoundField DataField="Emp_Name" HeaderText="Assinged to" />
<asp:TemplateField>
<ItemTemplate>
<asp:Button runat="server" ID="btnSelect" Text="Select" OnClick="btnSelect_Click" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
when i select one of the rows , i get hits error below :
Server Error in '/' Application.
Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
Source Error:
Line 103:
Line 104: GridViewRow SelectedRow = ((sender as Button).NamingContainer as GridViewRow);
Line 105: Session["GVAssetList_ID"] = GVAssetList.DataKeys[SelectedRow.RowIndex].Value;
Line 106:
Line 107:
Source File: e:\MyTestWebSite\Admin\UpdateAssetV2.aspx.cs Line: 105
why this happenes and how to solve.
thanks