数据网格分页:当前页面索引值无效。 它必须 >= 0

发布于 2024-07-15 12:54:13 字数 212 浏览 9 评论 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

戏蝶舞 2024-07-22 12:54:13

当您进行某些更改时,您需要重置到第 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.

死开点丶别碍眼 2024-07-22 12:54:13

我有一个启用分页的数据网格。 我根据过滤条件在数据网格中显示结果。 我已经过滤了数据,现在有 2 页。 当我转到第二页时,我再次执行搜索功能以缩小结果范围。 然后我收到类似的错误

“当前页面索引值无效。它必须 >= 0 且 <
PageCount+datagrid分页"

我确信第二次搜索只会产生比前一次更少的页面数。如何解决这个问题?
错误显示:

当前页面索引值。 它必须是 >= 0 且 < 页数。

我解决了问题

protected void btnSearchLibrary_Click(object sender, EventArgs e)
{
    if(!String.IsNullOrEmpty(txtSearchLibraryNo.Text.Trim()))
    oBookReceiptDTO.LibraryCardNo = txtSearchLibraryNo.Text.Trim();
    gvBooksReceiptList.CurrentPageIndex = 0;
    FillGridViewBookReceiptList(oBookReceiptDTO);
}

注意: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

"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 this problem ?
Error show:

CurrentPageIndex value. It must be >= 0 and < the PageCount.

I solved the problem

protected void btnSearchLibrary_Click(object sender, EventArgs e)
{
    if(!String.IsNullOrEmpty(txtSearchLibraryNo.Text.Trim()))
    oBookReceiptDTO.LibraryCardNo = txtSearchLibraryNo.Text.Trim();
    gvBooksReceiptList.CurrentPageIndex = 0;
    FillGridViewBookReceiptList(oBookReceiptDTO);
}

NOTE: gvBooksReceiptList.CurrentPageIndex = 0; this is the line I used to solve the problem.

伴梦长久 2024-07-22 12:54:13

另一个建议是仅在 PageCount 发生更改并导致 HttpException 时重置 CurrentPageIndex。 该代码片段基于 Les Smith 的示例

    Try
        dataGrid1.DataBind()
    Catch
        ' We possibly don't have the correct PageCount.
        dataGrid1.CurrentPageIndex = 0
        dataGrid1.DataBind()
    End Try

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.

    Try
        dataGrid1.DataBind()
    Catch
        ' We possibly don't have the correct PageCount.
        dataGrid1.CurrentPageIndex = 0
        dataGrid1.DataBind()
    End Try
此岸叶落 2024-07-22 12:54:13

您可以转到第一页,也可以捕获异常并移至您喜欢的任何页面。 如果您要从最后一页删除一条记录,您可能需要移至上一页。

 try
    {
       grid.DataSource = dao.PopulateGrid();
       grid.DataBind();
    }
     catch
    {
     if (grid.CurrentPageIndex >= grid.PageCount)
      {
        grid.CurrentPageIndex -= 1;
        grid.DataSource = dao.PopulateGrid();
        grid.DataBind();
      }
    }

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.

 try
    {
       grid.DataSource = dao.PopulateGrid();
       grid.DataBind();
    }
     catch
    {
     if (grid.CurrentPageIndex >= grid.PageCount)
      {
        grid.CurrentPageIndex -= 1;
        grid.DataSource = dao.PopulateGrid();
        grid.DataBind();
      }
    }
千と千尋 2024-07-22 12:54:13

就我而言,我所做的是每次在数据网格控件上加载的数据发生更改时始终应用重置当前页面索引的行。

DataGrid.CurrentPageIndex = 0

DataGrid.DataSource = 数据表/数据集

DataGrid.DataBind()

这是因为将数据源绑定到数据网格时抛出的异常并不总是页面计数不一致。

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.

DataGrid.CurrentPageIndex = 0

DataGrid.DataSource = Datatable/Dataset

DataGrid.DataBind()

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文