PageIndexChange in datagrid

Discussion in 'ASP .Net Datagrid Control' started by pietaster, Feb 17, 2004.

  1. pietaster

    pietaster Guest

    I have a datagrid that I need to allow paging. The datagrid only gets
    loaded when !IsPostBack. If this is the case paging does not work. If
    I load the datagrid IsPostBack then the paging works. Then the problem
    would be that when paged the data will get loaded twice. Once from
    Page_Load and once from datagrid_PageIndexChange. What should I
    do?????

    My paging event gets loaded in OnInt. AllowPaging and PageSize and
    other things needed for paging are also loaded in OnInt.

    Thanks.
    pietaster
    pietaster, Feb 17, 2004
    #1
    1. Advertising

  2. pietaster

    Renato Aloi Guest

    The default behavior of the datagrid's pagin' is:

    Not IsPostBack (first time load)
    - On Page load: DataBind the datagrid

    IsPostBack (every other load)
    - On Page load: Skips binding
    - On Page Index change: Set the new page index and databind the datagrid

    The best way to do this is combining not is postback with a routine to
    databind the datagrid, like this:

    ' 1. {
    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
    System.EventArgs) Handles MyBase.Load

    If Not IsPostBack Then
    Me.loadDataGrid()
    End If

    End Sub
    ' }

    ' 2. {
    Private Sub DataGrid1_PageIndexChanged(ByVal source As Object, ByVal e As
    System.Web.UI.WebControls.DataGridPageChangedEventArgs) Handles
    DataGrid1.PageIndexChanged

    Me.DataGrid1.CurrentPageIndex = e.NewPageIndex
    Me.loadDataGrid()

    End Sub
    ' }

    ' 3. {
    Private Sub loadDataGrid()

    Me.DataGrid1.DataSource = whateverDataSource
    Me.DataGrid1.DataBind()

    End Sub
    ' }

    []s
    Graccs

    "pietaster" <> escreveu na mensagem
    news:...
    > I have a datagrid that I need to allow paging. The datagrid only gets
    > loaded when !IsPostBack. If this is the case paging does not work. If
    > I load the datagrid IsPostBack then the paging works. Then the problem
    > would be that when paged the data will get loaded twice. Once from
    > Page_Load and once from datagrid_PageIndexChange. What should I
    > do?????
    >
    > My paging event gets loaded in OnInt. AllowPaging and PageSize and
    > other things needed for paging are also loaded in OnInt.
    >
    > Thanks.
    > pietaster
    Renato Aloi, Feb 17, 2004
    #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. Dave
    Replies:
    0
    Views:
    433
  2. BK Kim

    datagrid in datagrid

    BK Kim, Feb 23, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    530
    Alvin Bruney [MVP]
    Mar 2, 2004
  3. Fabio Mastria
    Replies:
    1
    Views:
    393
    Fabio Mastria
    Apr 3, 2008
  4. Andreas Klemt
    Replies:
    0
    Views:
    270
    Andreas Klemt
    Oct 8, 2003
  5. sa siva via .NET 247

    SortCommand and PageIndexChange event not firing

    sa siva via .NET 247, Mar 24, 2005, in forum: ASP .Net Datagrid Control
    Replies:
    2
    Views:
    149
    Cole Trickle
    May 5, 2005
Loading...

Share This Page