Datagrid CurrentPageIndex causes error on last page

T

Toby Mills

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 :)
 
A

Alan Corbett \(.NET MVP\)

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.
 
T

Toby Mills

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 :)
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top