
Gridview datakeys
本程序错误提示:“GridViewName.DataKeys[SelectedIndex].Value.Tostring();索引超出范围。必须为非负值并小于集合大小。....
本程序错误提示:“GridViewName.DataKeys[SelectedIndex].Value.Tostring(); 索引超出范围。必须为非负值并小于集合大小。..."查看microsoft visual studio 2005 帮助文档的例子:<%@ Page language="C#" %><script runat="server"> void CustomersGridView_SelectedIndexChanged(Object sender, EventArgs e) { // Determine the index of the selected row. int index = CustomersGridView.SelectedIndex; // Display the primary key value of the selected row. Message.Text = "The primary key value of the selected row is " + CustomersGridView.DataKeys[index].Value.ToString() + "."; }</script><html> <body> <form runat="server"> <h3>GridView DataKeys Example</h3> <asp:label id="Message" forecolor="Red" runat="server"/> <br/><br/> <asp:gridview id="CustomersGridView" datasourceid="CustomersSource" autogeneratecolumns="true" emptydatatext="No data available." autogenerateselectbutton="true" datakeynames="CustomerID" onselectedindexchanged="CustomersGridView_SelectedIndexChanged" runat="server"> </asp:gridview> <!-- This example uses Microsoft SQL Server and connects --> <!-- to the Northwind sample database. Use an ASP.NET --> <!-- expression to retrieve the connection string value --> <!-- from the Web.config file. --> <asp:sqldatasource id="CustomersSource" selectcommand="Select [CustomerID], [CompanyName], [Address], [City], [PostalCode], [Country] From [Customers]" connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>" runat="server"/> </form> </body></html>新建一个空网站,把代码复制过去,还是会提示错误:”CustomersGridView.DataKeys[index].Value.ToString() 索引超出范围。必须为非负值并小于集合大小“ 怎么回事啊??应该怎么解决??
展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询