Solved

refresh gridview on the same page after modifying data

Posted on 2011-02-15
5
1,170 Views
Last Modified: 2012-05-11
I have a gridview that has allowPaging and AllowSorting set to true. It is bound to a sqldatasource with the selectCommand firing a sql query.
The sqldatasource has EnableCaching = true, and caching duration = "60". The idea is to run the paging, sorting, etc from the cache.

A separate dataUpdate event updates the data that is being loaded in the grid view, but I am not able to see the change in the gridview data till 30 seconds (caching duration) .

What is the best way to force refresh the gridview data by the dataUpdate event?

I came across this artice that tells to use CacheKeyDependency,  but when I implemented it, the gridview gets refreshed at every dataUpdate event, but also the paging and sorting fires the sqldatasource Selectcommand sql query. I want this query to be fired only on dataUpdate.

http://beatgates.blogspot.com/2009/11/simple-way-to-invalidate-sqldatasource.html


0
Comment
Question by:patd1
  • 3
  • 2
5 Comments
 
LVL 10

Expert Comment

by:himanshut
ID: 34901942
in your code behind for dataUpdate event, re-bind the grid, but do check for Page.IsPostBack in your page load.

Also for grid add up AutoPostBack = "tru" in your aspx page.

It should do the job :)
0
 

Author Comment

by:patd1
ID: 34902128
I have re-bind in the dataUpdate and Autopostback for the grid is set to true.
It does the grid update, but also fires the query on paging sorting events, which I don't want. That is why i enabled caching to true, so that these events do not fire the query.

However, when I check for Page.IsPostBack in the dataUpdate event before rebinding the grid, the grid does not get refreshed.

Thanks.

0
 
LVL 10

Expert Comment

by:himanshut
ID: 34902183
in Page_Load()
{
 if(!Page.IsPostBack)
{
// bind the grid
}
else // if page is posting back the data
{
   //check if DataUpdate == true
    {
       //re-bind grid
     }
}


Cheers!
0
 

Accepted Solution

by:
patd1 earned 0 total points
ID: 34930363
I was doing the the cacheKeyDependency removal and creation in the wrong way.
It worked by changing it as follows:
Cache.Remove(SQLDataSource1.CacheKeyDependency);
Cache[SQLDataSource1.CacheKeyDependency] = new object();

Open in new window

0
 

Author Closing Comment

by:patd1
ID: 34959269
found a different solution.
0

Featured Post

ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you haven’t already, I encourage you to read the first article (http://www.experts-exchange.com/articles/18680/An-Introduction-to-R-Programming-and-R-Studio.html) in my series to gain a basic foundation of R and R Studio.  You will also find the …
The purpose of this article is to demonstrate how we can use conditional statements using Python.
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question