Solved

refresh gridview on the same page after modifying data

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Data Saving(2) 2 41
ADO.NET ENTITY DATA MODEL 3 30
Connection String 16 41
C# MVC and a global static factory that never dies 4 42
This article will show, step by step, how to integrate R code into a R Sweave document
When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…

939 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

11 Experts available now in Live!

Get 1:1 Help Now