By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,432 Members | 790 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,432 IT Pros & Developers. It's quick & easy.

GridView paging/sorting vs. Retrieving data from database

P: n/a
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.
Apr 10 '08 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.