GridView paging/sorting vs. Retrieving data from database
am 10.04.2008 15:00:05 von gnewsgroupUsually, 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.