[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.aspnet.webcontrols

Re: Invalid CurrentPageIndex Value

andreranieri

2/19/2004 12:24:00 AM

Doug Holland <doug.holland@rhi.com> wrote in message news:<A6A84F3C-6011-495A-991C-0ABF16EC4493@microsoft.com>...
> Hi There
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.




>
> 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 instance
>
> 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 advance
>
> Doug Holland