Why does my datagrid.databind blow up?

C

carlor

Hi there,

I'm at a loss to resolve this so I'm hoping someone can enlighten me.

I have a search user control that contains and displays a results user
control if files are found. If any results are found, I set the results UC
datatable property to the results datatable, set the results datagrid's
datasource to the dataTable and perform a dataBind. That works fine.

I am using paging on the dataGrid and that works. The problem I'm running
into is when I perform another find after changing pages on the dataGrid.
Let's say my first result set produced 5 pages of results and I select and
display the 3rd page. I then perform another find which produces a result set
of only 1 page. The results UC is still there so I set the UC's dataTable
property to the new results set, set the dataGrid's dataSource to the new
dataTable (because this is a postback the dataSource is nothing) and perform
a dataBind.

This is where it blows up. Because the dataGrid's CurrentPageIndex is set to
the 3rd page but the new result set only has 1 page, I get the following
exception:

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

Am I missing something painfully obvious? Any idea how I resolve this problem?


Thanks a bunch,

Carlo.
 
P

Phillip Williams

Set the CurrentPageIndex to 0 when you execute a new search because the
databind by itself does not reset that variable.
 

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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top