Solved

refresh gridview on the same page after modifying data

Posted on 2011-02-15
5
1,160 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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Check my code out(2) 1 35
Get String split 5 33
c# if statement weird reaction 3 30
Achieve json result 2 35
Windows Script Host (WSH) has been part of Windows since Windows NT4. Windows Script Host provides architecture for building dynamic scripts that consist of a core object model, scripting hosts, and scripting engines. The key components of Window…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This video teaches viewers about errors in exception handling.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

743 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now