Invalid CurrentPageIndex Value

Discussion in 'ASP .Net Web Controls' started by Doug Holland, Jan 26, 2004.

  1. Doug Holland

    Doug Holland Guest

    Hi Ther

    I have a DataGrid on a webform which is causing an HttpException in the following code when it transitions from showing all of the packages in the system (12 on two pages) to only linked packages (3 on one page)

    m_DataGrid.DataSource = _list; // _list is an ArrayList instanc

    if(m_DataGrid.CurrentPageIndex > m_DataGrid.PageCount

    m_DataGrid.CurrentPageIndex = 0


    m_DataGrid.DataBind()

    The if statement never evaluates to true and as such the CurrentPageIndex is not reset to zero at this point and therefore an appropriate value for CurrentPageIndex exists just prior to the call to m_DataGrid.DataBind(), within that method call though the CurrentPageIndex becomes invalid and the HttpException is thrown

    How do I handle this situation

    Thanks in advanc

    Doug Holland
     
    Doug Holland, Jan 26, 2004
    #1
    1. Advertising

  2. Doug Holland

    Andre Guest

    Doug Holland <> wrote in message news:<>...
    > Hi There

    I ran into a similar message "Invalid CurrentPageIndex value. It must
    be >= 0 and < the PageCount." under the same circumstances.

    It turned out that I was making multiple trips to the database from
    separate subroutines: the first time to initially bind data to the
    datagrid and then every time my CurrentIndexChanged subroutine ran. I
    had declared the dataset separately in each subroutine, I don't think
    the event handler liked this very much.

    My (successful) solution was to declare the dataset as a protected
    object for the class, then reference the same dataset table instance
    from both subroutines. It eliminated this error, and reduced calls to
    the database.




    >
    > I have a DataGrid on a webform which is causing an HttpException in the following code when it transitions from showing all of the packages in the system (12 on two pages) to only linked packages (3 on one page):
    >
    > m_DataGrid.DataSource = _list; // _list is an ArrayList instance
    >
    > if(m_DataGrid.CurrentPageIndex > m_DataGrid.PageCount)
    > {
    > m_DataGrid.CurrentPageIndex = 0;
    > }
    >
    > m_DataGrid.DataBind();
    >
    > The if statement never evaluates to true and as such the CurrentPageIndex is not reset to zero at this point and therefore an appropriate value for CurrentPageIndex exists just prior to the call to m_DataGrid.DataBind(), within that method call though the CurrentPageIndex becomes invalid and the HttpException is thrown.
    >
    > How do I handle this situation?
    >
    > Thanks in advance
    >
    > Doug Holland
     
    Andre, Feb 19, 2004
    #2
    1. Advertising

  3. Doug Holland

    Andre Guest

    Also, on second review, I don't see where your datasource,

    e.g. dgMyGrid.DataSource = ds.Tables["MyDataSetTable"];
     
    Andre, Feb 19, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. jm
    Replies:
    0
    Views:
    471
  2. George Smith
    Replies:
    2
    Views:
    1,443
    Alvin Bruney [MVP]
    Apr 27, 2007
  3. Franck
    Replies:
    4
    Views:
    9,224
    sangsharma
    Jun 29, 2007
  4. Daniel Bauke

    strange Invalid CurrentPageIndex value

    Daniel Bauke, Nov 17, 2003, in forum: ASP .Net Datagrid Control
    Replies:
    3
    Views:
    208
    Alvin Bruney
    Nov 18, 2003
  5. Juan G.
    Replies:
    5
    Views:
    288
    Teemu Keiski
    Jul 12, 2005
Loading...

Share This Page