strange Invalid CurrentPageIndex value

Discussion in 'ASP .Net Datagrid Control' started by Daniel Bauke, Nov 17, 2003.

  1. Daniel Bauke

    Daniel Bauke Guest

    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..


    --
    Daniel Bauke; http://www.bonkey.pl.eu.org; {happiness==bike&&unix;}
    Daniel Bauke, Nov 17, 2003
    #1
    1. Advertising

  2. Daniel Bauke

    Alvin Guest

    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" <> wrote in message
    news:vxxojmbrul63.3mkqq6q5106v$...
    > 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..
    >
    >
    > --
    > Daniel Bauke; http://www.bonkey.pl.eu.org; {happiness==bike&&unix;}
    Alvin, Nov 17, 2003
    #2
    1. Advertising

  3. Daniel Bauke

    Daniel Bauke Guest

    On Mon, 17 Nov 2003 15:34:38 -0600, Alvin wrote:

    > 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 :)

    --
    Daniel Bauke; http://www.bonkey.pl.eu.org; {happiness==bike&&unix;}
    Daniel Bauke, Nov 17, 2003
    #3
  4. Daniel Bauke

    Alvin Bruney Guest

    > 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.

    --


    -----------
    Got TidBits?
    Get it here: www.networkip.net/tidbits
    "Daniel Bauke" <> wrote in message
    news:p...
    > On Mon, 17 Nov 2003 15:34:38 -0600, Alvin wrote:
    >
    > > 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 :)
    >
    > --
    > Daniel Bauke; http://www.bonkey.pl.eu.org; {happiness==bike&&unix;}
    Alvin Bruney, Nov 18, 2003
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. jm
    Replies:
    0
    Views:
    455
  2. George Smith
    Replies:
    2
    Views:
    1,412
    Alvin Bruney [MVP]
    Apr 27, 2007
  3. Franck
    Replies:
    4
    Views:
    9,182
    sangsharma
    Jun 29, 2007
  4. Juan G.
    Replies:
    5
    Views:
    265
    Teemu Keiski
    Jul 12, 2005
  5. Franck
    Replies:
    0
    Views:
    131
    Franck
    Oct 21, 2005
Loading...

Share This Page