Datagrid Paging: Invalid CurrentPageIndex value. It must be> = 0

I have a datagrid with paging support. I am showing the results in a datagrid based on the filter condition. I have filtered the data and now has 2 pages. when I go to page 2. and again I perform a marine function to narrow the results. Then I get the error "Invalid CurrentPageIndex value. It must be> = 0 and <page page PageCount + datagrid". I am sure that the second search will display fewer pages than the previous one. How to solve a problem? thanks in advance

+3
source share
5 answers

When making certain changes, you need to reset on page 1. This includes filtering the changes. To a large extent, anytime you change the number of rows that may be available for your grid, return to page 1.

+5
source

I have a datagrid with paging support. I am showing the results in a datagrid based on the filter condition. I have filtered the data and now has 2 pages. When I go to the second page, I again perform a search function to narrow the results. Then I get an error like

"Invalid CurrentPageIndex value. It must be> = 0 and <PageCount + datagrid paging"

, , . ? :

CurrentPageIndex. >= 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; , .

+1

reset CurrentPageIndex PageCount HttpException. Les Smith .

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

, . , .

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

In my case, what I did was always apply a line that returns the current page index every time there is a change in the data that is loaded in the data network control.

DataGrid.CurrentPageIndex = 0

DataGrid.DataSource = Datatable / Dataset

DataGrid.DataBind ()

This is because the exception that occurred when linking a data source to a data network would be an odd number of pages.

0
source

Source: https://habr.com/ru/post/1705073/


All Articles