473,405 Members | 2,334 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Using caching with an editable gridview

In an ASP.Net 2.0 page using SQL Server 2K, I have a editable gridview
that is bound to a SQLDataSource using stored procedures for its select
and update queries. The grid works fine but is slow due to rebinding
on postbacks when the edit, save or cancel buttons are clicked. So I
set "enablecache = True" for the SQLDataSource and it is much,much
faster. Clicking on edit or cancel (when in edit mode) refreshes the
grid much faster. But the problem I can't seem to solve is after
editing a row and saving it, the cache does not get updated and the
grid shows the old value from the cache. Instead of using the
enablecache property, I was thinking of saving the data to the cache
manually and rebinding only when the save button is clicked. I used to
do this by saving the dataset to cache. But I don't see a way to save
the results of a SQLDataSource "select" into a cache. Is a dataset even
generated? Is there some way to refresh the cache when the save button
is clicked without using the SQL dependency feature, which I would not
rather use at this point? I don't know if the SQL dependency feature
would update the cache that quickly anyway. Any suggestions would be
greatly appreciated. Thanks in advance for any help.

Jul 12 '06 #1
2 2009
I found a property that is supposed to work to expire the cache but of
course it does not work. I have found others that have not been able
to get this to work.

Set the CacheKeyDependency property to something like "MyKey"

Sub Page_Load(sender As Object, e As EventArgs)
If Not IsPostBack Then
Cache(SqlDataSource1.CacheKeyDependency) = someData
End If
End Sub

Then removing it from the cache, supposedly causes the cache to get
refreshed.

Sub OnItemUpdated(sender As Object, e As DetailsViewUpdatedEventArgs)
Cache.Remove(SqlDataSource1.CacheKeyDependency)
GridView1.DataBind()
End Sub

Anyone have any luck getting this to work?

dba56 wrote:
In an ASP.Net 2.0 page using SQL Server 2K, I have a editable gridview
that is bound to a SQLDataSource using stored procedures for its select
and update queries. The grid works fine but is slow due to rebinding
on postbacks when the edit, save or cancel buttons are clicked. So I
set "enablecache = True" for the SQLDataSource and it is much,much
faster. Clicking on edit or cancel (when in edit mode) refreshes the
grid much faster. But the problem I can't seem to solve is after
editing a row and saving it, the cache does not get updated and the
grid shows the old value from the cache. Instead of using the
enablecache property, I was thinking of saving the data to the cache
manually and rebinding only when the save button is clicked. I used to
do this by saving the dataset to cache. But I don't see a way to save
the results of a SQLDataSource "select" into a cache. Is a dataset even
generated? Is there some way to refresh the cache when the save button
is clicked without using the SQL dependency feature, which I would not
rather use at this point? I don't know if the SQL dependency feature
would update the cache that quickly anyway. Any suggestions would be
greatly appreciated. Thanks in advance for any help.
Jul 12 '06 #2
I tried so many different variations of setting the CacheKeyDependency
and nothing worked. I was able to use a little trick to get the cache
cleared. Its not a great way to do things, but this is a small
intranet web page that will be used by 2 people in our marketing
department. So it will suffice for us. In case anyone else out there
needs a quick and dirty asp.net 2.0 page, here's what worked for me:

It seems that when caching is enabled for a SqlDatasource object, a key
is generated that includes the select statement, any parameters,
CacheDuration value, CacheExpirationPolicy value and some other items.
If any of these items change, the key is changed and the cache is
expired causing the select statement to execute and regenerate the
data.

I initially have the CacheDuration set to 3600. In the
SqlDatasource_Updated event, I increment or decrement the CacheDuration
value by 5 seconds depending on the last value and then rebind the
gridview. I also store this value in a session variable. When a page
reloads, I found that the CacheDuration is automatically reset to the
original default value (3600 in my case), which would in turn cause the
cache to expire again. But since at that point I do want to use cache,
I use the session variable in the page load event to reset it back to
the last incremented/decremented value. Works like a charm and the
page is only slower when updating a row but at least you will see the
updated row, not the old cached row.

dba56 wrote:
I found a property that is supposed to work to expire the cache but of
course it does not work. I have found others that have not been able
to get this to work.

Set the CacheKeyDependency property to something like "MyKey"

Sub Page_Load(sender As Object, e As EventArgs)
If Not IsPostBack Then
Cache(SqlDataSource1.CacheKeyDependency) = someData
End If
End Sub

Then removing it from the cache, supposedly causes the cache to get
refreshed.

Sub OnItemUpdated(sender As Object, e As DetailsViewUpdatedEventArgs)
Cache.Remove(SqlDataSource1.CacheKeyDependency)
GridView1.DataBind()
End Sub

Anyone have any luck getting this to work?
Jul 13 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Janaka | last post by:
Hi All, I'm having a problem with Page Output caching on a page that contains a DataGrid. Basically the page pulls up some data for sales information from the DB. Some of this has to be...
1
by: craigkenisston | last post by:
I have a grid attached to an objectdatasource from which just one field is editable. For the update method I have a method with two parameters, the key of the record and the column to be updated....
1
by: SDRoy | last post by:
Hi I am using asp:BoundField code for my GridView Control. Something like: <asp:GridView ID="GridView2" runat="server" AutoGenerateEditButton="True" OnRowEditing="GridView2_RowEditing"> ...
3
by: Mike P | last post by:
Is it possible to make an editable gridview so that certain rows are editable and other are not editable, dependent upon a value in one of the rows columns? *** Sent via Developersdex...
1
by: ad | last post by:
Hi, We can set a GridView editable or deleteable in desgin time. How can I set them in run time?
0
by: Frank | last post by:
Hello All, I am working with VS.NET 2005 and I have an editable GridView whose HTML markup is shown below. In short, when the user clicks on the Edit button, one of the textboxes is replaced...
0
by: Frank | last post by:
Hello All, I am working with VS.NET 2005 and I have an editable GridView whose HTML markup is shown below. In short, when the user clicks on the Edit button, one of the textboxes is replaced...
1
by: news-server.maine.rr.com | last post by:
Hi, I have the following bound to a database column and want the URL field to be editable in the GridView control. When the "Edit" link is clicked the field remains readOnly. ...
1
by: Steve Kershaw | last post by:
Hi, I have a problem in which I'm using a GridView with an ObjectDataSource as a data source. The problem is that when I use the ObjectDataSource UPDATE routine I must have the key column...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.