索引超出范围.必须为非负数并且小于集合的大小.参数名称:编辑索引 [英] Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index on edit

查看:119
本文介绍了索引超出范围.必须为非负数并且小于集合的大小.参数名称:编辑索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用ajax maksed编辑扩展器进行压光机控制.
但是,当我单击网格的编辑按钮时,它不起作用,使用调试时,它显示索引超出范围的错误.必须为非负数并且小于集合的大小.参数名称:编辑时的索引...
当我评论Ajax隐藏的编辑扩展器时,网格可以完美地与edit配合.
所以告诉我是什么问题?????
提前感谢...

I am using ajax maksed edit extender for calender control.
but using this when i click the edit button of my grid it does not react and using debug it shows the error that Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index on edit...
when i commented the ajax masked edit extender the grid works perfect with edit.
So tell me what is the problem?????
Thanx in advance...

推荐答案

该错误表示您正在访问索引小于零或大于其容量的集合.请注意,索引基于0,所以如果您有3个项目,则可用索引为0,1,2.
尝试单步执行代码,您将能够找出哪个集合引发此错误.

--mit
The error means you are accessing a collection with index less than zero or greater than its capacity. Note that the index is 0 based so if you have 3 items, the available indexes are 0,1,2.
Try stepping through your code and you will be able to figure out which collection is throwing this error.

--Amit


当对象中没有没有这样的索引时,就会出现此错误

关于您有3张B,C,D卡,但我要输入"A"或"Z"

例如.
grid1有2行
this error comes when there is no such index available in object

it''s about you have 3 cards B,C,D but I am asking for ''A'' or ''Z''

eg.
grid1 have 2 rows
rowno   index
1       0
2       1




现在,如果我们尝试获取第三行(平均索引= 2),则会发生这种错误




Now if we try to fetch 3rd row (means index=2) this kind of error occur

grid1.rows[2].cells[0].value // it will throw exception



检查您的代码是否发生与上述示例相同的事情

解决错误
写下保护条件,使这种情况永远不会发生
例如.



check your code some where same thing happened as above example

to solve error,
write protective conditions so that such situation never occur
eg.

if (RowId > grid1.rows.count-1) //condition is protecting inner statement so, if suppose RowId=3 then it will not go to execute inner statement
    grid1.rows[RowId].cells[0].value



祝您编码愉快!
:)



Happy Coding!
:)




由于您没有将代码和问题一起发布,因此我们可以假设您的代码将如何.

当您请求数组或集合中不存在的索引时,将发生IndexOutOfRange异常.

如何重现此异常:示例
Hi,

As you have not post your code along with question we can just assume how your code would be.

IndexOutOfRange exception occur when you are requesting for nonexisting index in the Array or Collection.

How to reproduce this exception : Example
int[] array = new int[100];
array[120] = 3; // Here 120 index is not exist as array is of size 100



有关更多信息,请参见: MSDN IndexOutOfRangeException [



For more information Refer : MSDN IndexOutOfRangeException[^]

Hope you findout your issue yourself. Next time when you post your question, also post the line of code where you are getting exception.

Thanks
-Amit Gajjar


这篇关于索引超出范围.必须为非负数并且小于集合的大小.参数名称:编辑索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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