代码之家  ›  专栏  ›  技术社区  ›  Shyju

数据报分页:无效的currentpageindex值。它必须是>0

  •  3
  • Shyju  · 技术社区  · 17 年前

    我有一个启用分页的数据报。我将根据筛选条件在数据报中显示结果。我已经过滤了数据,现在它有两页了。当我进入第二页时。我再次执行seacring函数来缩小结果范围。然后我得到一个错误,比如“无效的currentpageindex值”。它必须是>=0和<pageCount+datagrid paging“我确信第二次搜索只会产生比前一次搜索更少的页数。如何解决这个问题?提前谢谢

    5 回复  |  直到 17 年前
        1
  •  5
  •   John Saunders    17 年前

    当您进行某些更改时,需要重置为第1页。这包括筛选更改。大多数情况下,只要更改网格中可用的行数,就返回到第1页。

        2
  •  1
  •   DaveShaw Thishin    14 年前

    我有一个启用分页的数据报。我将根据筛选条件在数据报中显示结果。我已经过滤了数据,现在它有两页了。当我转到第2页时,我再次执行搜索功能以缩小结果范围。然后我得到一个错误

    “无效的currentpageindex值。它必须是>=0和<the pagecount+数据报分页“

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

    当前页索引值。它必须是>=0和<pageCount。

    我解决了这个问题

    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; 这是我用来解决问题的那条线。

        3
  •  0
  •   Boggin    15 年前

    另一个建议是,只在pageCount更改并导致httpException时重置currentPageIndex。代码片段基于Les Smith的 example .

        Try
            dataGrid1.DataBind()
        Catch
            ' We possibly don't have the correct PageCount.
            dataGrid1.CurrentPageIndex = 0
            dataGrid1.DataBind()
        End Try
    
        4
  •  0
  •   Christian Rios    13 年前

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

     try
        {
           grid.DataSource = dao.PopulateGrid();
           grid.DataBind();
        }
         catch
        {
         if (grid.CurrentPageIndex >= grid.PageCount)
          {
            grid.CurrentPageIndex -= 1;
            grid.DataSource = dao.PopulateGrid();
            grid.DataBind();
          }
        }
    
        5
  •  0
  •   nelson    12 年前

    对于我的情况,我所做的就是每次在数据网格控件上加载的数据发生更改时都应用行重置当前页索引。

    datagrid.currentpageindex=0

    datagrid.datasource=数据表/数据集

    datagrid.databind()。

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

    推荐文章