DataGrid - Sorting & Paging

Discussion in 'ASP .Net' started by pmanno, May 6, 2005.

  1. pmanno

    pmanno Guest

    If I have a page with a DataGrid that is bound to a DataTable that is
    populated by a query to a database and I want to enable sorting and
    paging, do I have to add the DataTable to the cache or will the
    viewstate hold the contents of the DataTable?

    Basically, I want to avoid hitting the database wherever I can. It
    seems that the DataTable has to be cached and the DataGrid re-bound, or
    the DataTable has to be re-populated from the database and the DataGrid
    re-bound whenever a postback occurs since the DataTable and therefore
    the data which is bound to the grid is discarded once the page renders.

    Thanks.
    pmanno, May 6, 2005
    #1
    1. Advertising

  2. pmanno

    Marina Guest

    Viewstate will only hold the contents of the grid. By contents I mean the
    HTML generated to display the contents of the data source.

    The datatable itself will not be there. So you have to recreate it, sort,
    and rebind.

    "pmanno" <> wrote in message
    news:...
    > If I have a page with a DataGrid that is bound to a DataTable that is
    > populated by a query to a database and I want to enable sorting and
    > paging, do I have to add the DataTable to the cache or will the
    > viewstate hold the contents of the DataTable?
    >
    > Basically, I want to avoid hitting the database wherever I can. It
    > seems that the DataTable has to be cached and the DataGrid re-bound, or
    > the DataTable has to be re-populated from the database and the DataGrid
    > re-bound whenever a postback occurs since the DataTable and therefore
    > the data which is bound to the grid is discarded once the page renders.
    >
    > Thanks.
    >
    Marina, May 6, 2005
    #2
    1. Advertising

  3. You need to add it to the cache, then re-sort it each page load

    --
    Regards

    John Timney
    ASP.NET MVP
    Microsoft Regional Director

    "pmanno" <> wrote in message
    news:...
    > If I have a page with a DataGrid that is bound to a DataTable that is
    > populated by a query to a database and I want to enable sorting and
    > paging, do I have to add the DataTable to the cache or will the
    > viewstate hold the contents of the DataTable?
    >
    > Basically, I want to avoid hitting the database wherever I can. It
    > seems that the DataTable has to be cached and the DataGrid re-bound, or
    > the DataTable has to be re-populated from the database and the DataGrid
    > re-bound whenever a postback occurs since the DataTable and therefore
    > the data which is bound to the grid is discarded once the page renders.
    >
    > Thanks.
    >
    John Timney \(ASP.NET MVP\), May 6, 2005
    #3
    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. Hajime Kusakabe

    DataGrid - sorting/paging problem

    Hajime Kusakabe, Jul 30, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    474
    Saravana
    Jul 31, 2003
  2. Mo
    Replies:
    1
    Views:
    4,181
    FFlannery
    Jan 30, 2004
  3. Henry
    Replies:
    1
    Views:
    380
    Frank Wisniewski
    Jul 21, 2004
  4. wh1974
    Replies:
    0
    Views:
    2,416
    wh1974
    Jan 12, 2005
  5. Red
    Replies:
    1
    Views:
    702
Loading...

Share This Page