strange Invalid CurrentPageIndex value

D

Daniel Bauke

i cannot find the rule why from time to time i'm receiving "Invalid
CurrentPageIndex value. It must be >= 0 and < the PageCount."

at the beginning it looked like it was something with weird browsers, but
looks like it's not a rule.

i suppose it started failing when i added:

protected void SearchResultsItemCreated(Object sender,
DataGridItemEventArgs e) {
DataGridItem item = e.Item;
if (item.ItemType == ListItemType.Pager) {
TableCell pager = (TableCell) item.Controls[0];
for (int i=0; i < pager.Controls.Count; i++) {
Control ctl = pager.Controls;
if (ctl is LinkButton) {
LinkButton lnk = (LinkButton) ctl;
lnk.CssClass = "navPage";
}

}
}
}

as a method for OnItemCreated.

stack trace of the error follows:

System.Web.HttpUnhandledException: Exception of type
System.Web.HttpUnhandledException was thrown. --->
System.Web.HttpException: Invalid CurrentPageIndex value. It must be >= 0
and < the PageCount.
at System.Web.UI.WebControls.DataGrid.CreateControlHierarchy(Boolean
useDataSource)
at System.Web.UI.WebControls.BaseDataList.OnDataBinding(EventArgs e)
at System.Web.UI.WebControls.BaseDataList.DataBind()
at PB.Portal.Site.Portlets.Common.Search.SearchResultsBind()
at
PB.Portal.Site.Portlets.Common.Search.SearchResults_PageIndexChanged(Object
source, DataGridPageChangedEventArgs e)
at
System.Web.UI.WebControls.DataGrid.OnPageIndexChanged(DataGridPageChangedE
ventArgs e)
at System.Web.UI.WebControls.DataGrid.OnBubbleEvent(Object source,
EventArgs e)
at System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args)
at System.Web.UI.WebControls.DataGridItem.OnBubbleEvent(Object source,
EventArgs e)
at System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args)
at System.Web.UI.WebControls.LinkButton.OnCommand(CommandEventArgs e)
at
System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.R
aisePostBackEvent(String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
sourceControl, String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
at System.Web.UI.Page.ProcessRequestMain()
--- End of inner exception stack trace ---
at System.Web.UI.Page.HandleError(Exception e)
at System.Web.UI.Page.ProcessRequestMain()
at System.Web.UI.Page.ProcessRequest()
at System.Web.UI.Page.ProcessRequest(HttpContext context)
at
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication+IExecutionS
tep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean&
completedSynchronously)

--------

on PageIndexChanged i have simple:

private void SearchResults_PageIndexChanged(object source,
System.Web.UI.WebControls.DataGridPageChangedEventArgs e) {
SearchResults.CurrentPageIndex = e.NewPageIndex;
SearchResultsBind();
}

and SearchResultsBind() does:

private void SearchResultsBind() {
SearchResults.PageSize = ResultsPerPage;
DataSet sr = SqlResult;
if (sr.Tables.Count > 0) {
DataView dv = sr.Tables[0].DefaultView;
dv.Sort = OrderBy;
SearchResults.DataSource = dv;
SearchResults.DataBind();
}
// ...
}


and.. i have no idea what it is..
 
A

Alvin

It's annoying isn't it? It's a bug (undocumented). I have seen it happen
mostly when you use paging select an item on one page and change the
datagrid so that this item on that particular page no longer exists. I've
gotten so fed up of it that I just put a catch block around the bind code
and reset the pageindex = 0;

catch(Exception)

{

//reset and hope for the best here tehehehe

BaseReport.CurrentPageIndex = 0;

BaseReport.DataSource = ds;

BaseReport.DataBind();

}


--


-----------
Got TidBits?
Get it here: www.networkip.net/tidbits
Daniel Bauke said:
i cannot find the rule why from time to time i'm receiving "Invalid
CurrentPageIndex value. It must be >= 0 and < the PageCount."

at the beginning it looked like it was something with weird browsers, but
looks like it's not a rule.

i suppose it started failing when i added:

protected void SearchResultsItemCreated(Object sender,
DataGridItemEventArgs e) {
DataGridItem item = e.Item;
if (item.ItemType == ListItemType.Pager) {
TableCell pager = (TableCell) item.Controls[0];
for (int i=0; i < pager.Controls.Count; i++) {
Control ctl = pager.Controls;
if (ctl is LinkButton) {
LinkButton lnk = (LinkButton) ctl;
lnk.CssClass = "navPage";
}

}
}
}

as a method for OnItemCreated.

stack trace of the error follows:

System.Web.HttpUnhandledException: Exception of type
System.Web.HttpUnhandledException was thrown. --->
System.Web.HttpException: Invalid CurrentPageIndex value. It must be >= 0
and < the PageCount.
at System.Web.UI.WebControls.DataGrid.CreateControlHierarchy(Boolean
useDataSource)
at System.Web.UI.WebControls.BaseDataList.OnDataBinding(EventArgs e)
at System.Web.UI.WebControls.BaseDataList.DataBind()
at PB.Portal.Site.Portlets.Common.Search.SearchResultsBind()
at
PB.Portal.Site.Portlets.Common.Search.SearchResults_PageIndexChanged(Object
source, DataGridPageChangedEventArgs e)
at
System.Web.UI.WebControls.DataGrid.OnPageIndexChanged(DataGridPageChangedE
ventArgs e)
at System.Web.UI.WebControls.DataGrid.OnBubbleEvent(Object source,
EventArgs e)
at System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args)
at System.Web.UI.WebControls.DataGridItem.OnBubbleEvent(Object source,
EventArgs e)
at System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args)
at System.Web.UI.WebControls.LinkButton.OnCommand(CommandEventArgs e)
at
System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.R
aisePostBackEvent(String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
sourceControl, String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
at System.Web.UI.Page.ProcessRequestMain()
--- End of inner exception stack trace ---
at System.Web.UI.Page.HandleError(Exception e)
at System.Web.UI.Page.ProcessRequestMain()
at System.Web.UI.Page.ProcessRequest()
at System.Web.UI.Page.ProcessRequest(HttpContext context)
at
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication+IExecutionS
tep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean&
completedSynchronously)

--------

on PageIndexChanged i have simple:

private void SearchResults_PageIndexChanged(object source,
System.Web.UI.WebControls.DataGridPageChangedEventArgs e) {
SearchResults.CurrentPageIndex = e.NewPageIndex;
SearchResultsBind();
}

and SearchResultsBind() does:

private void SearchResultsBind() {
SearchResults.PageSize = ResultsPerPage;
DataSet sr = SqlResult;
if (sr.Tables.Count > 0) {
DataView dv = sr.Tables[0].DefaultView;
dv.Sort = OrderBy;
SearchResults.DataSource = dv;
SearchResults.DataBind();
}
// ...
}


and.. i have no idea what it is..
 
D

Daniel Bauke

It's annoying isn't it? It's a bug (undocumented). I have seen it happen
mostly when you use paging select an item on one page and change the
datagrid so that this item on that particular page no longer exists. I've
gotten so fed up of it that I just put a catch block around the bind code
and reset the pageindex = 0;

well.. i'try to fix it that way. but

it's not the first time i need to kick something to make it work.. e.g. the
latest.. why on earth i get 'Arithmetic overflow error converting
expression to data type int' about once per 10k queries.. 8-o
and what is the only solution i found? try .. catch :)
 
A

Alvin Bruney

latest.. why on earth i get 'Arithmetic overflow error converting
expression to data type int' about once per 10k queries.. 8-o
and what is the only solution i found? try .. catch :)

actually there was a patch out for this one, but i forget how long ago and
where the patch is.
 

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,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top