views:

16

answers:

1

My Gridview is refreshing its datasource when the edit button is clicked. How can I prevent this from happening? This isn't much of a problem when there aren't a lot of records, but when there are many it takes awhile. The data is already loaded so the edit button shouldn't need to reload the data. The edit button is a template edit button, and I'm using an SQL Datasource that connects to an Oracle database. The SQL datasource uses a control parameter that points to a dropdownlist.

Any guidance would be appreciated.

+1  A: 

I see two possibilities, both leveraging the SqlDataSource control.

Enabling caching on the SqlDataSource control is my favorite. This might not actually solve your problem, though. Setting the cache to something reasonable has the potential to speed up a lot of your page beyond the simple editing scenario, though, so I favor tweeking things there.

The second option would be to handle the Updating event on the SqlDataSource control. During the Updating event, you can set e.Cancel to true if you determine that you are under the influence of a post back for editing. Doing so will cause the update to be skipped. This might not actually work if the GridView relies on the update to remember the items pulled in a prior display request, though. I haven't used it recently enough to be certain if this is the case. If it is, you may end up having to handle the Updated event on initial page display and store the resulting data in a self-rolled faux-cache. You can see that this might get complicated fast...

Which you use (and how you use them) depends a lot on use case details. This should get you started looking in the right direction, though.

Jacob Proffitt
I enabled Caching, made an enormous difference right off the bat. The users who edit the data won't be touching the same data so it shouldn't make a difference that it is cached. I left the defaults as they were.
Cj Anderson
Excellent. I'm glad that was a solution that worked.
Jacob Proffitt