Paging a datagrid

Discussion in 'ASP .Net Datagrid Control' started by Fabiano, Nov 27, 2003.

  1. Fabiano

    Fabiano Guest

    Please,

    i've created a datagrid that allow numbered paging.
    But when i click over a page that must be called, i get this error:

    System.Web.HttpException: Invalid CurrentPageIndex value. It must be >= 0
    and < the PageCount

    at my page, on Paging Event i'm using the commands bellow:

    private void DataGrid1_PageIndexChanged(object source,
    System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
    {
    DataGrid1.CurrentPageIndex = e.NewPageIndex;
    DataGrid1.DataBind();
    }



    I get the error at the DataBind function. what could be wrong?



    Tks

    Fabiano
     
    Fabiano, Nov 27, 2003
    #1
    1. Advertising

  2. hi,

    This is a mistake because you don't fill datasourse in the datagrid!
    You have to fill datagrid again after selected CurrentPageIndex.

    For example:

    DataGrid1.CurrentPageIndex = e.NewPageIndex;
    DataGrid1.DataSourse = ...//Your sourse. and then you can make databind of
    datagrid.
    DataGrid1.DataBind();

    bye-bye.

    The Best Regards,
    Web Developer
    Michael Tkachev

    "Fabiano" <> wrote in message
    news:...
    > Please,
    >
    > i've created a datagrid that allow numbered paging.
    > But when i click over a page that must be called, i get this error:
    >
    > System.Web.HttpException: Invalid CurrentPageIndex value. It must be >= 0
    > and < the PageCount
    >
    > at my page, on Paging Event i'm using the commands bellow:
    >
    > private void DataGrid1_PageIndexChanged(object source,
    > System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
    > {
    > DataGrid1.CurrentPageIndex = e.NewPageIndex;
    > DataGrid1.DataBind();
    > }
    >
    >
    >
    > I get the error at the DataBind function. what could be wrong?
    >
    >
    >
    > Tks
    >
    > Fabiano
    >
    >
     
    Michael Tkachev, Nov 28, 2003
    #2
    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. =?Utf-8?B?UGF0cmljay5PLklnZQ==?=

    DataSet paging vs Datareader paging

    =?Utf-8?B?UGF0cmljay5PLklnZQ==?=, Oct 8, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    10,772
    Scott Allen
    Oct 8, 2004
  2. Roger
    Replies:
    0
    Views:
    970
    Roger
    Dec 28, 2004
  3. wh1974
    Replies:
    0
    Views:
    2,451
    wh1974
    Jan 12, 2005
  4. Red
    Replies:
    1
    Views:
    733
  5. Green Start Button

    DataGrid.Items.Count and DataGrid Paging...

    Green Start Button, Aug 4, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    5,835
    agravar
    Aug 2, 2006
Loading...

Share This Page