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

M

Meg

Hi All,

I am having a problem with paging in datagrid and need
some idea as to how to handle the problem
1. the datagrid is first filled with a select * all
2. the datgrid shows 10 pages 12345678910
3. the first page shows 10 records
4. if do a keyword search on the full dataset the selected
records are returned...I can repeat this many times while
my page index is set to page 1.
5. I can also repeat the select all and the above steps
still work (page index is set to page 1)
6. If I move off of page 1 to another page like say page 5.
page 5 and it's records work
7. if I do a select * all the page count stays at page 5
(most likely because of the !postback in page load)
8. I if I do a keyword search and I am not set to page 1 I
get the error message "Invalid CurrentPageIndex value. It
must be >= 0 and < the PageCount".
9. how can I initiallize the dataset back to page 1
programmicaly?

Any help is greatly appreciated.

Meg
 
K

Kevin Cunningham

Did u try to set dataGrid.CurrentPageIndex = 1. The internals of the
datagrid should work out the details for you, assuming you have a valid data
source.
 
K

Kevin Cunningham

ooops, sorry the CurrentPageIndex is zero-base ... dataGrid.CurrentPageIndex
= 0.
 
M

Meg

Yes I did. But I still get the same error.
-----Original Message-----
Did u try to set dataGrid.CurrentPageIndex = 1. The internals of the
datagrid should work out the details for you, assuming you have a valid data
source.

--
Kevin Cunningham
Software Architects





.
 
Joined
Jun 20, 2006
Messages
1
Reaction score
0
I tried testing if (dgResults.CurrentPageIndex > dgResults.PageCount ) // dgResults is my datagrid
but the problem was that the PageCount and CurrentPageIndex don't seem to be defined for the current query until after the databinding.

try
{
dgResults.DataBind();
}
catch (Exception)
{
if ( ! (dgResults.CurrentPageIndex < dgResults.PageCount))
{
if ( ! dgResults.PageCount.Equals(0)) // before the first binding, both are zero // this is likely always true
{
dgResults.CurrentPageIndex = dgResults.PageCount - 1;
dgResults.DataBind();
}
}
else
{
dgResults.DataBind(); // This is just to display any remaining error conditions
}
}
 

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

Top