How to refresh an ASP.NET GridView automatically at regular intervals

A common requirement is to refresh the GridView after regular intervals. ASP.NET contains the Timer control which comes in very handy to achieve such requirements. Here's how to do so:

Add the GridView and the Timer control inside an ASP.NET AJAX UpdatePanel as shown below :

<asp:UpdatePanel ID="UpdatePanel1" runat="server">


<asp:Timer ID="Timer1" runat="server" Interval="3600" ontick="Timer1_Tick"></asp:Timer>

<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" DataKeyNames="CustomerID"

DataSourceID="SqlDataSource1" AllowPaging="True" AllowSorting="True">


<asp:BoundField DataField="CustomerID" HeaderText="CustomerID" ReadOnly="True" SortExpression="CustomerID" />

<asp:BoundField DataField="CompanyName" HeaderText="CompanyName" SortExpression="CompanyName" />

<asp:BoundField DataField="ContactName" HeaderText="ContactName" SortExpression="ContactName" />

<asp:BoundField DataField="Address" HeaderText="Address" SortExpression="Address" />

<asp:BoundField DataField="City" HeaderText="City" SortExpression="City" />





Then in the code behind, add the following code which refreshes the GridView after every minute


protected void Timer1_Tick(object sender, EventArgs e)





Protected Sub Timer1_Tick(ByVal sender As Object, ByVal e As EventArgs)


End Sub

Will you give this article a +1 ? Thanks in advance

About The Author

Suprotim Agarwal
Suprotim Agarwal, ASP.NET Architecture MVP (Microsoft Most Valuable Professional) works as an Architect Consultant and provides consultancy on how to design and develop Web applications.

Suprotim is also the founder and primary contributor to DevCurry, DotNetCurry and SQLServerCurry. He is the Editor of a Developer Magazine called DNC Magazine. He has also written two EBooks 51 Recipes using jQuery with ASP.NET Controls. and The Absolutely Awesome jQuery CookBook

Follow him on twitter @suprotimagarwal


20 Responses to "How to refresh an ASP.NET GridView automatically at regular intervals"
  1. Anonymous said...
    October 15, 2009 at 3:44 PM

    Thank you and best of luck with the book.

  2. Anonymous said...
    June 16, 2010 at 3:49 AM

    sank youu

  3. Rickson Menezes said...
    November 25, 2010 at 2:09 AM

    Gives me an error, Update Panel requires ScriptManager

  4. Rickson Menezes said...
    November 25, 2010 at 2:25 AM

    I added a script Manager tag just above the Update Panel and it worked. It was updating my gridview every x seconds

  5. Anonymous said...
    December 12, 2010 at 6:07 PM

    Hello, im getting a PageRequestManagerParseErrorException, i have the code just like you suggest, what might be going wrong?

    Thank you.

  6. Suprotim Agarwal said...
    December 12, 2010 at 7:07 PM

    For the PageRequestManagerParseErrorException error, try this link

  7. Anonymous said...
    April 5, 2011 at 5:08 AM

    some of the function within the grid not work??

  8. Rahul Ostwal said...
    October 5, 2011 at 3:16 AM

    I am filling data after every 5 min. but by this code first time it take 5 min. to fill grid. how to avoid this?

  9. Pål Sølvberg said...
    June 19, 2012 at 12:11 AM

    Hi Rahul.
    You just have to fire the Databinder code in PageLoad, like this:

    protected void Page_Load(object sender, EventArgs e)




  10. Anonymous said...
    August 6, 2012 at 3:14 PM

    LO MAS GRANDE MUCHAS GRACIAS!!!!!!!!!!!!!!!!!!!!!!!!!


  11. Anonymous said...
    January 3, 2013 at 4:00 AM

    Simply gr8.........

  12. DIM said...
    December 20, 2013 at 12:22 AM

    Thanks for great article!!!!What we can do if we have 2 datagridviews and we want update every 5 seconds with different select commands both???

  13. Alex Segura said...
    July 22, 2014 at 12:24 PM

    Appreciate it!

  14. lingmaaki said...
    September 29, 2014 at 11:22 PM

    Check here..all about..Asp.Net Gridview


  15. Kalyani Bothra said...
    October 27, 2014 at 11:41 PM

    Thanks for this article. It was very beneficial for us.

  16. Rational Rogue said...
    September 21, 2015 at 2:27 AM

    I know I'm quite late to this comment thread but I'm a bit green when it comes to ASPX gridview and I could use some feedback.

    I have three gridviews with different sql query results being displayed that have paginated results. These gridview forms will be displayed on a monitor for an entire department and will need to automatically iterate through the paged results every two to three minutes continuously.

    While I am familiar enough with PHP to make this happen. I'm utterly lost when it comes to making this happen in aspx. Can you offer some very simple and straight forward feedback on how I might get this working?

  17. Rational Rogue said...
    September 29, 2015 at 1:35 PM

    I have successfully added the GridView and Timer control inside my ASPX.NET page and have updated the associated VB.NET file with the code noted. I also ran into the ScriptManager issue which I've added successfully. However, the gridview is not paging automatically.

    Is the C# code a requirement? I am extremely new to this, so thanks in advance for your patience with my question.

  18. Suprotim Agarwal said...
    September 29, 2015 at 7:18 PM

    In addition to automated Paging, do you want to be able to Sort and Paginate manually too? C# is not a requirement but the VB.NET code I posted was done using a translation tool. I know only C#.

  19. Rational Rogue said...
    September 29, 2015 at 7:42 PM

    Thanks so much for responding. I was finally able to get one of the gridviews looping through the pages results on a timer. :-)

  20. Suprotim Agarwal said...
    September 29, 2015 at 8:50 PM

    Glad to hear that!


Copyright © 2009-2016 All Rights Reserved for by Suprotim Agarwal | Terms and Conditions