GridView paging/sorting vs. Retrieving data from database

G

gnewsgroup

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top