Force GridView to Refresh in ASP.NET

You can force gridview to referesh its data by calling GridViews.DataBind() function in the code behind.

I have also come across a couple of others solutions that does the same. The one that works best is to use databind() on gridview

This is the most elegant solution. As an example, lets say you have a GridView that displays data from a table. You have another FormView that inserts data into the gridview. If you insert the data from FormView, you will notice that gridview does not updates the data. To fix this, select the FormView, go to properties, create the ItemInserted event for the form and put this code in it

This will cause the gridview to refresh. As soon as you add the data, Gridview will automatically display it. What actually happens is, DataBind() forces page fresh. When page is reloaded, it reloads the new data while it maintains its present state. Everything is so fast you don’t seem to notice it.

Other Solutions

Someone has commented that you have to call databind on both SQLDataSource and the gridview to refresh data as follows

In my case I confirmed, binding on datasoruce is not needed at least in this case.

Yet another Solution

This was a problematic solution. It caused my delete in gridview not work. Don’t know why exactly was so, May be I put it in the wrong function but it did work after refreshing the gridview.

2 Responses to Force GridView to Refresh in ASP.NET
  1. anita says:

    I was looking for this solution. I found it here. Thanks for the post. In my case I have a table with only one column which is date field. Its the primary key too.
    The first solution you mentioned is the best


  2. William says:


Leave a Reply

Your email address will not be published. Required fields are marked *