Datagrid CurrentPageIndex causes error on last page

Discussion in 'ASP .Net Datagrid Control' started by Toby Mills, Sep 16, 2003.

  1. Toby Mills

    Toby Mills Guest

    I have a placeholder control which is populated with several datagrids
    at runtime. These grids all use paging, but I have to do it manually,
    with buttons also added to the placeholder.

    The paging works fine, except when I get to the last page, either by
    using:

    grdResult.CurrentPageIndex = grdResult.PageCount - 1

    or:

    grdResult.CurrentPageIndex += 1

    On the last page, if the number of records differs from the page size
    by more than one, it raises an error (see below). e.g. a page size of
    10 works fine when I have 440 records (last page has 10 records), fine
    for 439 records (last page has 9 records), but crashes on the last
    page for 438 records (last page has 8 records)

    The error message is:

    An error has occurred because a control with auto-generated id
    'grdResult1:_ctl10:_ctl0' could not be located to raise a postback
    event. To avoid this error, explicitly set the ID property of controls
    that raise postback events.

    The control to which it is refering,'grdResult1:_ctl10:_ctl0', is a
    checkbox, which forms part of a template in a template column in the
    datagrid. The error occurs regardless of the state of the checkbox

    can anybody help me with this? Can anybody even recreate this problem?

    Thanks,
    Toby Mills :)
    Toby Mills, Sep 16, 2003
    #1
    1. Advertising

  2. Toby, are you sure the control to which it is referring isn't actually a row
    that ISN'T THERE since you're not filling that last page?

    Try adding a specific ID to each item within the control, if you haven't
    already.


    "Toby Mills" <> wrote in message
    news:...
    > I have a placeholder control which is populated with several datagrids
    > at runtime. These grids all use paging, but I have to do it manually,
    > with buttons also added to the placeholder.
    >
    > The paging works fine, except when I get to the last page, either by
    > using:
    >
    > grdResult.CurrentPageIndex = grdResult.PageCount - 1
    >
    > or:
    >
    > grdResult.CurrentPageIndex += 1
    >
    > On the last page, if the number of records differs from the page size
    > by more than one, it raises an error (see below). e.g. a page size of
    > 10 works fine when I have 440 records (last page has 10 records), fine
    > for 439 records (last page has 9 records), but crashes on the last
    > page for 438 records (last page has 8 records)
    >
    > The error message is:
    >
    > An error has occurred because a control with auto-generated id
    > 'grdResult1:_ctl10:_ctl0' could not be located to raise a postback
    > event. To avoid this error, explicitly set the ID property of controls
    > that raise postback events.
    >
    > The control to which it is refering,'grdResult1:_ctl10:_ctl0', is a
    > checkbox, which forms part of a template in a template column in the
    > datagrid. The error occurs regardless of the state of the checkbox
    >
    > can anybody help me with this? Can anybody even recreate this problem?
    >
    > Thanks,
    > Toby Mills :)
    Alan Corbett \(.NET MVP\), Sep 17, 2003
    #2
    1. Advertising

  3. Toby Mills

    Toby Mills Guest

    Hi Alan,

    I eventually turned my brain on and did exactly what the error message
    suggested. I provided the checkbox with an ID. Then all worked great!

    I still don't quite understand WHY though!

    Toby :)

    "Alan Corbett \(.NET MVP\)" <> wrote in message news:<>...
    > Toby, are you sure the control to which it is referring isn't actually a row
    > that ISN'T THERE since you're not filling that last page?
    >
    > Try adding a specific ID to each item within the control, if you haven't
    > already.
    >
    >
    > "Toby Mills" <> wrote in message
    > news:...
    > > I have a placeholder control which is populated with several datagrids
    > > at runtime. These grids all use paging, but I have to do it manually,
    > > with buttons also added to the placeholder.
    > >
    > > The paging works fine, except when I get to the last page, either by
    > > using:
    > >
    > > grdResult.CurrentPageIndex = grdResult.PageCount - 1
    > >
    > > or:
    > >
    > > grdResult.CurrentPageIndex += 1
    > >
    > > On the last page, if the number of records differs from the page size
    > > by more than one, it raises an error (see below). e.g. a page size of
    > > 10 works fine when I have 440 records (last page has 10 records), fine
    > > for 439 records (last page has 9 records), but crashes on the last
    > > page for 438 records (last page has 8 records)
    > >
    > > The error message is:
    > >
    > > An error has occurred because a control with auto-generated id
    > > 'grdResult1:_ctl10:_ctl0' could not be located to raise a postback
    > > event. To avoid this error, explicitly set the ID property of controls
    > > that raise postback events.
    > >
    > > The control to which it is refering,'grdResult1:_ctl10:_ctl0', is a
    > > checkbox, which forms part of a template in a template column in the
    > > datagrid. The error occurs regardless of the state of the checkbox
    > >
    > > can anybody help me with this? Can anybody even recreate this problem?
    > >
    > > Thanks,
    > > Toby Mills :)
    Toby Mills, Sep 23, 2003
    #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. CW
    Replies:
    1
    Views:
    487
    Andrew de la Harpe
    Apr 1, 2004
  2. =?Utf-8?B?U2FuZHk=?=

    Invalid currentPageIndex error message

    =?Utf-8?B?U2FuZHk=?=, Apr 17, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    547
    =?Utf-8?B?U2FuZHk=?=
    Apr 18, 2005
  3. =?Utf-8?B?Q2FsdmluIEtE?=
    Replies:
    2
    Views:
    653
    =?Utf-8?B?Q2FsdmluIEtE?=
    Aug 29, 2005
  4. Jim Mitchell

    Moving to the correct CurrentPageIndex in the datagrid.

    Jim Mitchell, Aug 6, 2003, in forum: ASP .Net Datagrid Control
    Replies:
    2
    Views:
    107
    Jim Mitchell
    Aug 7, 2003
  5. Spike

    Invalid CurrentPageIndex error

    Spike, May 3, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    13
    Views:
    266
    Alvin Bruney [MVP]
    May 7, 2004
Loading...

Share This Page