Force GridView to Refresh in ASP.NET

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

GridView.DataBind(); /* this will referesh the gridview */

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

 protected void FormView2_ItemInserted(object sender, FormViewInsertedEventArgs e)

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

GridView1.SelectedIndex = -1;

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.

This entry was posted in Troubeleshoot. Bookmark the permalink.

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

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s