views:

160

answers:

3

Hi,

We are working on Grid Views in an ASP.NET application.

Here we would like to avoid the database calls for binding dataset/data table to grid view whenever a user clicks on sort (column sorting), pagination links or whenever he updates a record.

Would you please let me know the best practice to handle it?

If would be great if you could also provide a reference document or web references (If needed).

Many Thanks, Regards, Nani.

+1  A: 

I think you will be hard pressed to make this optimization of any use. Are the GridView sort/update/page functions taking a lot (inordinate) of time to complete? You might need to look at the database design as well.

Matthew Jones
+2  A: 

You have a few options here, but they all have their own pitfalls and are often worse than just hitting the database again. Some possibilities:

  • Save the DataSource in the Cache. See Caching Application Data for a good overview.

  • For small amounts of serializable data, you can consider saving it to the Page's ViewState. The drawback of this is that it increases the size of the HTML you send to the client, so you need to balance that against the time you may be saving by not hitting the database again. Scott Mitchell's Understanding ViewState is a great introduction to this.

  • Just for completeness' sake - this one is terrible: you can save the GridView's DataSource in the user's Session. This eats up your web server's memory; you probably should not use this technique except for prototyping (in which case you might as well hit the database again).

Finally, you should absolutely take seriously the advice in these other answers.

Jeff Sternal
+2  A: 

If you want your users to have extensive sorting, pagination and editing capabilities without frequent database calls, you'd be better off creating a fat Windows client. Web apps in general are better for thin clients.

You could do all your sorting and editing client-side with JavaScript, but that would be an incredibly bad idea. I would say: let your server and your database do what they're good at, and don't be overly concerned with minimizing their roles in your application.

MusiGenesis
+1: yes to the hundredth power.
Jeff Sternal
@Jeff: um, +1 to the hundredth power is still 1. :)
MusiGenesis