数据网格分页:当前页面索引值无效。 它必须 >= 0
我有一个启用分页的数据网格。 我根据过滤条件在数据网格中显示结果。 我已经过滤了数据,现在有 2 页。 当我转到第二页时。 我正在再次执行搜索功能以缩小结果范围。 然后我收到类似“无效的 CurrentPageIndex 值。它必须 >= 0 且 < PageCount+datagrid 分页”的错误,我确信第二次搜索只会产生比前一个搜索更少的页面数。 如何解决这个问题? 提前致谢
I have a datagrid with paging enabled. I am displaying the results in datagrid based on a filtering condition. I have filtered the data and it has now 2 pages. when i go to 2 nd page. and i am doing the seacrhing function once again to narrow down the results. Then I am getting an error like "Invalid CurrentPageIndex value. It must be >= 0 and < the PageCount+datagrid paging" I am sure that the second search will produce only less number of pages than the previous one. How to solve ths problem ? Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
当您进行某些更改时,您需要重置到第 1 页。这包括过滤更改。 几乎,每当您更改网格可用的行数时,请返回到第 1 页。
When you make certain changes, you need to reset to page 1. That includes filtering changes. Pretty much, any time you change the number of rows that might be available to your grid, go back to page 1.
我有一个启用分页的数据网格。 我根据过滤条件在数据网格中显示结果。 我已经过滤了数据,现在有 2 页。 当我转到第二页时,我再次执行搜索功能以缩小结果范围。 然后我收到类似的错误
我确信第二次搜索只会产生比前一次更少的页面数。如何解决这个问题?
错误显示:
我解决了问题
注意:
gvBooksReceiptList.CurrentPageIndex = 0;
这是我用来解决问题的行。I have a datagrid with paging enabled. I am displaying the results in datagrid based on a filtering condition. I have filtered the data and it has now 2 pages. When I go to 2nd page and I am doing the searching function once again to narrow down the results. Then I am getting an error like
I am sure that the second search will produce only less number of pages than the previous one. How to solve this problem ?
Error show:
I solved the problem
NOTE:
gvBooksReceiptList.CurrentPageIndex = 0;
this is the line I used to solve the problem.另一个建议是仅在 PageCount 发生更改并导致 HttpException 时重置 CurrentPageIndex。 该代码片段基于 Les Smith 的示例。
Another suggestion is to only reset the CurrentPageIndex when the PageCount has changed and causes the HttpException. The code fragment is based on Les Smith's example.
您可以转到第一页,也可以捕获异常并移至您喜欢的任何页面。 如果您要从最后一页删除一条记录,您可能需要移至上一页。
You can either go to the first page or catch the exception and move to whatever page you like. If you are deleting one record from the last page, you might want to move to the previous one.
就我而言,我所做的是每次在数据网格控件上加载的数据发生更改时始终应用重置当前页面索引的行。
这是因为将数据源绑定到数据网格时抛出的异常并不总是页面计数不一致。
For my case, what I did is to always apply the line resetting the current page index every time there is a change of data that is being loaded on the Data Grid control.
This is because it is not all the time that the exception thrown when binding a data source to the Data Grid would be the inconsistent page count.