DataGrid Paging doesnt page!

Discussion in 'ASP .Net' started by Dee, Apr 18, 2005.

  1. Dee

    Dee Guest

    Hi
    The paging numbers of my DataGrid dont actually page. What can be the cause?
    Everyting else seems to work.
    Thanks
    Dee
     
    Dee, Apr 18, 2005
    #1
    1. Advertising

  2. Dee

    Scott M. Guest

    What code have you entered into the PageIndexChanged event handler?


    "Dee" <dee@home> wrote in message
    news:%...
    > Hi
    > The paging numbers of my DataGrid dont actually page. What can be the
    > cause?
    > Everyting else seems to work.
    > Thanks
    > Dee
    >
    >
     
    Scott M., Apr 18, 2005
    #2
    1. Advertising

  3. Dee

    Dee Guest

    Thanks Scott,
    I dodnt know I needd to handle that event.
    It workd now. I added:

    DataGrid1.CurrentPageIndex = e.NewPageIndex
    DataGrid1.DataBind()

    It's intersting that the paging works without thr DataBind() call but have
    to click on the page TWICE!


    "Scott M." <> wrote in message
    news:...
    > What code have you entered into the PageIndexChanged event handler?
    >
    >
    > "Dee" <dee@home> wrote in message
    > news:%...
    > > Hi
    > > The paging numbers of my DataGrid dont actually page. What can be the
    > > cause?
    > > Everyting else seems to work.
    > > Thanks
    > > Dee
    > >
    > >

    >
    >
     
    Dee, Apr 18, 2005
    #3
  4. Dee

    Jeebu Guest

    HI
    set the property of datagrid to AllowPaging="True"
    then
    on the grid_page index changed event
    write the code

    grid.CurrentPageIndex = e.NewPageIndex ;

    and then write the code for connecting to the datbase
    "Dee" <dee@home> wrote in message news:%...
    > Hi
    > The paging numbers of my DataGrid dont actually page. What can be the cause?
    > Everyting else seems to work.
    > Thanks
    > Dee
    >
    >
     
    Jeebu, Apr 18, 2005
    #4
  5. Dee

    Scott M. Guest

    You must ALWAYS call the databind method after making any kind of change to
    the datagrid that affects what data the grid is showing.

    The reason you'd have to click the pager twice without the extra databind
    call is that the grid uses ViewState to remember, not only the data that is
    was showing, but also other "state" information such as what page of data
    was showing, what sort order was in effect, what row was being edited or was
    selected, etc.

    Without the databind call, the grid is bound to its data in Page_Load
    (that's where you do have a databind call, right?) and the first click sets
    the page correctly but doesn't update the grid with the new page of data
    because no databind call took place AFTER setting the page to show, the
    second click causes the grid to bind to its data in Page_Load as well, but
    now the grid is "remembering" via ViewState what page of data to display
    BEFORE the databind call takes place.

    In general, your page load event handler should look like this:

    datagrid.datasource = someDataSource
    If Not IsPostBack Then
    datagrid.databind
    End If

    and then at the end of EACH and EVERY datagrid event handler where the data
    would change in some way (sortCommand, PageIndexChanged, EditCommand,
    DeleteCommand, SortCommand, CancelCommand)

    datagrid.databind



    "Dee" <dee@home> wrote in message
    news:%...
    > Thanks Scott,
    > I dodnt know I needd to handle that event.
    > It workd now. I added:
    >
    > DataGrid1.CurrentPageIndex = e.NewPageIndex
    > DataGrid1.DataBind()
    >
    > It's intersting that the paging works without thr DataBind() call but have
    > to click on the page TWICE!
    >
    >
    > "Scott M." <> wrote in message
    > news:...
    >> What code have you entered into the PageIndexChanged event handler?
    >>
    >>
    >> "Dee" <dee@home> wrote in message
    >> news:%...
    >> > Hi
    >> > The paging numbers of my DataGrid dont actually page. What can be the
    >> > cause?
    >> > Everyting else seems to work.
    >> > Thanks
    >> > Dee
    >> >
    >> >

    >>
    >>

    >
    >
     
    Scott M., Apr 18, 2005
    #5
  6. Dee

    Dee Guest

    Wow
    Great explanation! Thanks very much.
    Dee

    "Scott M." <> wrote in message
    news:#b$...
    > You must ALWAYS call the databind method after making any kind of change

    to
    > the datagrid that affects what data the grid is showing.
    >
    > The reason you'd have to click the pager twice without the extra databind
    > call is that the grid uses ViewState to remember, not only the data that

    is
    > was showing, but also other "state" information such as what page of data
    > was showing, what sort order was in effect, what row was being edited or

    was
    > selected, etc.
    >
    > Without the databind call, the grid is bound to its data in Page_Load
    > (that's where you do have a databind call, right?) and the first click

    sets
    > the page correctly but doesn't update the grid with the new page of data
    > because no databind call took place AFTER setting the page to show, the
    > second click causes the grid to bind to its data in Page_Load as well, but
    > now the grid is "remembering" via ViewState what page of data to display
    > BEFORE the databind call takes place.
    >
    > In general, your page load event handler should look like this:
    >
    > datagrid.datasource = someDataSource
    > If Not IsPostBack Then
    > datagrid.databind
    > End If
    >
    > and then at the end of EACH and EVERY datagrid event handler where the

    data
    > would change in some way (sortCommand, PageIndexChanged, EditCommand,
    > DeleteCommand, SortCommand, CancelCommand)
    >
    > datagrid.databind
    >
    >
    >
    > "Dee" <dee@home> wrote in message
    > news:%...
    > > Thanks Scott,
    > > I dodnt know I needd to handle that event.
    > > It workd now. I added:
    > >
    > > DataGrid1.CurrentPageIndex = e.NewPageIndex
    > > DataGrid1.DataBind()
    > >
    > > It's intersting that the paging works without thr DataBind() call but

    have
    > > to click on the page TWICE!
    > >
    > >
    > > "Scott M." <> wrote in message
    > > news:...
    > >> What code have you entered into the PageIndexChanged event handler?
    > >>
    > >>
    > >> "Dee" <dee@home> wrote in message
    > >> news:%...
    > >> > Hi
    > >> > The paging numbers of my DataGrid dont actually page. What can be the
    > >> > cause?
    > >> > Everyting else seems to work.
    > >> > Thanks
    > >> > Dee
    > >> >
    > >> >
    > >>
    > >>

    > >
    > >

    >
    >
     
    Dee, Apr 19, 2005
    #6
  7. Dee

    Scott M. Guest

    No problem. Good luck.


    "Dee" <dee@home> wrote in message
    news:%...
    > Wow
    > Great explanation! Thanks very much.
    > Dee
    >
    > "Scott M." <> wrote in message
    > news:#b$...
    >> You must ALWAYS call the databind method after making any kind of change

    > to
    >> the datagrid that affects what data the grid is showing.
    >>
    >> The reason you'd have to click the pager twice without the extra databind
    >> call is that the grid uses ViewState to remember, not only the data that

    > is
    >> was showing, but also other "state" information such as what page of data
    >> was showing, what sort order was in effect, what row was being edited or

    > was
    >> selected, etc.
    >>
    >> Without the databind call, the grid is bound to its data in Page_Load
    >> (that's where you do have a databind call, right?) and the first click

    > sets
    >> the page correctly but doesn't update the grid with the new page of data
    >> because no databind call took place AFTER setting the page to show, the
    >> second click causes the grid to bind to its data in Page_Load as well,
    >> but
    >> now the grid is "remembering" via ViewState what page of data to display
    >> BEFORE the databind call takes place.
    >>
    >> In general, your page load event handler should look like this:
    >>
    >> datagrid.datasource = someDataSource
    >> If Not IsPostBack Then
    >> datagrid.databind
    >> End If
    >>
    >> and then at the end of EACH and EVERY datagrid event handler where the

    > data
    >> would change in some way (sortCommand, PageIndexChanged, EditCommand,
    >> DeleteCommand, SortCommand, CancelCommand)
    >>
    >> datagrid.databind
    >>
    >>
    >>
    >> "Dee" <dee@home> wrote in message
    >> news:%...
    >> > Thanks Scott,
    >> > I dodnt know I needd to handle that event.
    >> > It workd now. I added:
    >> >
    >> > DataGrid1.CurrentPageIndex = e.NewPageIndex
    >> > DataGrid1.DataBind()
    >> >
    >> > It's intersting that the paging works without thr DataBind() call but

    > have
    >> > to click on the page TWICE!
    >> >
    >> >
    >> > "Scott M." <> wrote in message
    >> > news:...
    >> >> What code have you entered into the PageIndexChanged event handler?
    >> >>
    >> >>
    >> >> "Dee" <dee@home> wrote in message
    >> >> news:%...
    >> >> > Hi
    >> >> > The paging numbers of my DataGrid dont actually page. What can be
    >> >> > the
    >> >> > cause?
    >> >> > Everyting else seems to work.
    >> >> > Thanks
    >> >> > Dee
    >> >> >
    >> >> >
    >> >>
    >> >>
    >> >
    >> >

    >>
    >>

    >
    >
     
    Scott M., Apr 19, 2005
    #7
    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,876
    Scott Allen
    Oct 8, 2004
  2. wh1974
    Replies:
    0
    Views:
    2,492
    wh1974
    Jan 12, 2005
  3. Red
    Replies:
    1
    Views:
    771
  4. Shapper
    Replies:
    2
    Views:
    623
    Guest
    Jun 22, 2005
  5. Replies:
    3
    Views:
    466
    alex23
    May 27, 2008
Loading...

Share This Page