Click here to Skip to main content
15,888,113 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
1) i want to update a grid automatically when ever database table get affected am using multiple widgets in my page so i cant reload the page
2) i just need to reload a dynamic user control's grid view
3) i ve separate user control for put entry ,if i put entry on one user control it should affect another user control's grid
these are all dynamic widgets so i need some sample code to auto update that grid whene ever db table get affected is it possible?
Posted
Updated 29-Jul-12 23:18pm
v3

1 - this is not possible. Your page cannot know when a table row is changed. All you can do is regular AJAX calls to CHECK if you have new data.

2 - This is not a new question. But, a grid view is a server concept, it does not exist on the client. You can't really reload it unless you use the hacky ASP.NET AJAX library to pretend that is what you are doing.

3 - No, it's not possible. The best you can do, is have all these pages calling timers to try to find out if there is data they need.
 
Share this answer
 
Comments
_Amy 30-Jul-12 3:07am    
Nice guideline. +5!
arunraju 30-Jul-12 5:26am    
Christian Graus thanks for your suggestion , i may have more than 10 same type of widgets in my page,in that case it will affect my db by keep hitting ,so when ever user putting entry i should get update in other user control
(i.e) comments on fb, that is same page but mine dynamic user controls
 
Share this answer
 
Comments
_Amy 30-Jul-12 6:54am    
Thank you arunraju.
Hi ,
Well you can do it using Timer
Chech this example will guide you
XML
<div>
     <asp:ScriptManager ID="ScriptManager1" runat="server">
     </asp:ScriptManager>
     <asp:Timer ID="Timer1" runat="server" ontick="Timer1_Tick" Interval="2000">
     </asp:Timer>
     <asp:UpdatePanel ID="UpdatePanel1" runat="server">
           <ContentTemplate>
               <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
           </ContentTemplate>
               <Triggers>

                   <asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" />

               </Triggers>
     </asp:UpdatePanel>
 </div>

C#
protected void Timer1_Tick(object sender, EventArgs e)
{
     //Rebind your Gridview 
}

Best Regards
M.Mitwalli
 
Share this answer
 
Comments
_Amy 30-Jul-12 3:07am    
Question is "If the database get affected"..
Mohamed Mitwalli 30-Jul-12 3:28am    
So how you will know there is some kind of modification happen in your database table my opinion using timer and checking continuously Well I'm ready to hear from you .
there is another solution but I'm still not sure how it will work .
_Amy 30-Jul-12 4:55am    
There is many database tricks through which we can come to know about that. Refreshing the page in every 2 sec is not the best practice.
Mohamed Mitwalli 30-Jul-12 5:33am    
Well agree with you it's not the best practice , Maybe this task will accomplish using notification service Well this what in my mind , so can you share any of this tricks .
_Amy 30-Jul-12 5:43am    
Check out my answer.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900