Solved

refresh gridview on the same page after modifying data

Posted on 2011-02-15
5
1,174 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

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…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This video teaches viewers about errors in exception handling.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

631 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