且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何避免此错误,GridView索引超出范围.必须为非负数,并且小于集合的大小.参数名称:索引

更新时间:2022-06-13 06:14:59

错误意味着要么现在有行,因此.Rows [0]为null或没有那么多单元格在您的行中.

注意,单元将基于零,因此可能不存在Cells [10].

但是,如果您仅调试代码,这对您来说很容易修复.在代码上放置一个断点,您可以确切地看到问题所在以及如何解决它.

请注意实际上哪一行代码会导致错误,然后您就会知道.
The error means that either there are now rows and therefore .Rows[0] is null or There are not that many cells in your row.

Note, the cells will be zero based so perhaps Cells[10] does not exist.

However, this is a very easy thing for you to fix on your own if you just debug the code. Put a breakpoint on the code and you can see exactly what the problem is and how to fix it.

Pay attention to which line of code actually causes the error and then you''ll know.


网格单元格索引从零开始,因此,如果您的表包含10列,则可能是网格列应从单元格[0]到单元格[9].
The grid cells index starts from zero, so probably if your table contains 10 columns, then your grid columns should start from cells[0] to cells[9].