GridView paging/sorting vs. Retrieving data from database

Discussion in 'ASP .Net' started by gnewsgroup, Apr 10, 2008.

  1. gnewsgroup

    gnewsgroup Guest

    Usually, when I implement the PageIndexChanging and the Sorting event
    handler of a GridView, I have to load the data from the db right
    inside either of this event handler and then bind it to the GridView,
    like so:

    protected void GridView1_PageIndexChanging(object sender,
    GridViewPageEventArgs e)
    {
    DataTable mytable = GetMyDataFromDb(blah, blah);
    GridView1.DataSource = mytable;
    GridView1.PageIndex = e.NewPageIndex;
    GridView1.DataBind();
    }

    Isn't this very inefficient? Because each time the page index is
    clicked I make a trip to the db and load the data.

    Is there a way to save us the additional trips to the db upon clicking
    of the page index (for paging) and the table header (for sorting)?

    I have been wondering about this for a while. Thank you very much.
    gnewsgroup, Apr 10, 2008
    #1
    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. ck388
    Replies:
    1
    Views:
    10,639
    Brock Allen
    Jun 6, 2005
  2. Christian Hofmann

    GridView sorting/ paging without Javascript?

    Christian Hofmann, Oct 20, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    929
    Christian Hofmann
    Oct 20, 2005
  3. tfsmag
    Replies:
    1
    Views:
    4,730
    tfsmag
    Mar 14, 2006
  4. MattC
    Replies:
    10
    Views:
    478
    Alexey Smirnov
    May 18, 2007
  5. Ryan Liu
    Replies:
    0
    Views:
    120
    Ryan Liu
    Dec 12, 2008
Loading...

Share This Page