views:

1265

answers:

2

I'm writing an internal web application that is used to look up credit checks. I'm using ASP.NET for this website.

I have a SQL Query that I have to query the credit check database and it returns a datatable of results. After the person clicks search, I run the query and bind the returned datatable to the Gridview every time the user clicks the search button.

This works fine, and it populates my gridview like it should.

How do I maintain the data that is bound to my gridview beyond postback? For example, lets say a person clicks Page 2 of the paginated gridview... how do I keep from losing the data of the gridview during that postback?

Currently I am storing the datatable in session[] but I don't think I should be doing this, because the size of this table is very large (sometimes hundreds of thousands of results!)

Do I need to re-query the database for each postback? The query takes a decent bit and I'd rather not if I could help it.

What is the common solution here?

A: 

Several things:

  • Clicking on "Page 2" should not result in a postback - it should be a simple GET request.
  • Do not allow GridView to store its data in the ViewState: cache data manually and "rebind" datasource on each request
  • Use ASP.NET MVC
Anton Gogolev
If there ~is~ a post back, what happens then? Say on something other than pagination.
I specifically mentioned that _pagination_ should not be implemented using postbacks. Generally speaking, all navigation should be implemented in terms of GET requests, not POSTs or anything.
Anton Gogolev
I would say that is a very moot point.
Ruslan
+1  A: 

If you are storing the data in the session I would make sure viewstate is turned off and you are rebinding it on each postback so at least your not storing all that data in 2 places.

You could also considered leaving the viewstate on and changing logic that grabs the session data to bring back one page of data at a time? You would take in the current page and JUST return that page's data so that you could get all the data at first and store it in the session. Then if any other postback actions occurred during that page view where nothing was really going on with the grid you wouldn't have to rebind each time.

I have found that most of the issues I have run across in the past due to too much data being displayed in a grid were more design issues and I would step back and look at the overall problem that was trying to be solved and implement another solution to not have to display so much data. Usually a customer/user asks for everything because they don't consider any alternatives or the impact of their request.

Kelsey