Invalid CurrentPageIndex Value

D

Doug Holland

Hi Ther

I have a DataGrid on a webform which is causing an HttpException in the following code when it transitions from showing all of the packages in the system (12 on two pages) to only linked packages (3 on one page)

m_DataGrid.DataSource = _list; // _list is an ArrayList instanc

if(m_DataGrid.CurrentPageIndex > m_DataGrid.PageCount

m_DataGrid.CurrentPageIndex = 0


m_DataGrid.DataBind()

The if statement never evaluates to true and as such the CurrentPageIndex is not reset to zero at this point and therefore an appropriate value for CurrentPageIndex exists just prior to the call to m_DataGrid.DataBind(), within that method call though the CurrentPageIndex becomes invalid and the HttpException is thrown

How do I handle this situation

Thanks in advanc

Doug Holland
 
A

Andre

Doug Holland said:
I ran into a similar message "Invalid CurrentPageIndex value. It must
be >= 0 and < the PageCount." under the same circumstances.

It turned out that I was making multiple trips to the database from
separate subroutines: the first time to initially bind data to the
datagrid and then every time my CurrentIndexChanged subroutine ran. I
had declared the dataset separately in each subroutine, I don't think
the event handler liked this very much.

My (successful) solution was to declare the dataset as a protected
object for the class, then reference the same dataset table instance
from both subroutines. It eliminated this error, and reduced calls to
the database.
 
A

Andre

Also, on second review, I don't see where your datasource,

e.g. dgMyGrid.DataSource = ds.Tables["MyDataSetTable"];
 

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,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top