我收到错误消息,请帮帮我 [英] I got Error Message please help me

查看:73
本文介绍了我收到错误消息,请帮帮我的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Server Error in '/GridView' 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 128:        //string currentExtension;
Line 129:
Line 130:        Id = Convert.ToInt32(GridView1.DataKeys[1].Value);
Line 131:
Line 132:        //currentTitleOfCourtesy = ((TextBox)r.FindControl("TitleOfCourtesyTextBox")).Text;
 

Source File: e:\Documents and Settings\Administrator\My Documents\Visual Studio 2010\WebSites\Subbu\SelectEdit\GridView\Edti3.aspx.cs    Line: 130 

Stack Trace: 


预先感谢您的答复.


advance thanks for your reply

推荐答案

DataKeys集合似乎为空.

尝试将您的代码更改为:

Try to change your code to something like:

if (GridView1 != null && GridView1.DataKeys.Count > 1)
{
    Id = Convert.ToInt32(GridView1.DataKeys[1].Value);
}


您可以在页面上显示代码吗?验证是否已设置DataKeyNames(用于grridview).只有设置了此属性,您才能获取DataKeys集合.
Could you show your code on the page. verify whether you have set the DataKeyNames(for grridview) or not. you can get the DataKeys collection only if you set this property.


Id = Convert.ToInt32(GridView1.DataKeys[1].Value);



此处的值可能是Empty..ie,而不是1到0.



Here the Value of may be Empty..ie check instead 1 to 0.

Id = Convert.ToInt32(GridView1.DataKeys[0].Value);


这篇关于我收到错误消息,请帮帮我的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆