?
Solved

refresh gridview on the same page after modifying data

Posted on 2011-02-15
5
Medium Priority
?
1,176 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

718 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