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

Discussion in 'ASP .Net Datagrid Control' started by Juan G., Jul 6, 2005.

  1. Juan G.

    Juan G. Guest

    I have a DataGrid in which I use paging, as well as Delete buttons. My
    program works perfectly, except when I attempt to delete the only item on the
    page; I have no trouble deleting an item when there are more than one item
    on a page. For example, I have a list that is three pages long; there is
    currently only one item on page 3. I receive the above error message when I
    try to delete this item. Do I need to include a special line of code to
    prevent this from happening?
     
    Juan G., Jul 6, 2005
    #1
    1. Advertising

  2. Juan G.

    Teemu Keiski Guest

    Teemu Keiski, Jul 6, 2005
    #2
    1. Advertising

  3. Juan G.

    Juan G. Guest

    Re: Invalid CurrentPageIndex value. It must be >= 0 and < the Page

    Thank you, Teemu. I read this thread, and I think I might understand. I code
    in VB.Net, so the C# answer was a little confusing. They mentioned this code:

    if ((DataGrid.Items.Count % DataGrid.PageSize) == 1
    && DataGrid.CurrentPageIndex != 0 )
    DataGrid.CurrentPageIndex = DataGrid.PageCount - 2;

    Would it be correct to translate this as:

    If (DataGrid.Items.Count OR DataGrid.PageSize = 1
    AND DataGrid.CurrentPageIndex NotEqual 0 ) Then
    DataGrid.CurrentPageIndex = DataGrid.PageCount - 2

    Also, do I place this command at the beginning of my Delete Row sub (BEFORE
    I delete the row)?

    Thanks again for your help.

    Juan G.

    "Teemu Keiski" wrote:

    > Hi,
    >
    > yes, it needs to be handled manually
    > http://forums.asp.net/798105/ShowPost.aspx
    >
    > --
    > Teemu Keiski
    > ASP.NET MVP, AspInsider
    > Finland, EU
    > http://blogs.aspadvice.com/joteke
    >
    >
    >
     
    Juan G., Jul 6, 2005
    #3
  4. Juan G.

    Juan G. Guest

    Re: Invalid CurrentPageIndex value. It must be >= 0 and < the Page

    I just did some research, and I think the correct VB.NET syntax would be:

    If ((Math.IEEERemainder(DataGrid.Items.Count, DataGrid.PageSize)=1) AndAlso
    (DataGrid.CurrentPageIndex <>0)) Then DataGrid.CurrentPageIndex =
    DataGrid.PageCount-2

    End If

    "Teemu Keiski" wrote:

    > Hi,
    >
    > yes, it needs to be handled manually
    > http://forums.asp.net/798105/ShowPost.aspx
    >
    > --
    > Teemu Keiski
    > ASP.NET MVP, AspInsider
    > Finland, EU
    > http://blogs.aspadvice.com/joteke
    >
    >
    >
     
    Juan G., Jul 6, 2005
    #4
  5. Juan G.

    Teemu Keiski Guest

    Re: Invalid CurrentPageIndex value. It must be >= 0 and < the Page

    Hello,

    it's crucial that you just have correct CurrentPageIndex when the grid is
    rebound again. So, if deleting would fail then you wouldn't change the
    index, but if it succeeds and you rebind the list, then you'd want to
    correct the index.

    --
    Teemu Keiski
    ASP.NET MVP, AspInsider
    Finland, EU
    http://blogs.aspadvice.com/joteke
     
    Teemu Keiski, Jul 12, 2005
    #5
  6. Juan G.

    Teemu Keiski Guest

    Re: Invalid CurrentPageIndex value. It must be >= 0 and < the Page

    And by the way

    if ((DataGrid.Items.Count % DataGrid.PageSize) == 1

    means modulus e.g

    If (DataGrid.Items.Count Mod DataGrid.PageSize) = 1

    --
    Teemu Keiski
    ASP.NET MVP, AspInsider
    Finland, EU
    http://blogs.aspadvice.com/joteke
     
    Teemu Keiski, Jul 12, 2005
    #6
    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:
    473
  2. George Smith
    Replies:
    2
    Views:
    1,450
    Alvin Bruney [MVP]
    Apr 27, 2007
  3. Franck
    Replies:
    4
    Views:
    9,249
    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:
    210
    Alvin Bruney
    Nov 18, 2003
  5. Franck
    Replies:
    0
    Views:
    146
    Franck
    Oct 21, 2005
Loading...

Share This Page