Search code examples
c#.netasp.netlinq-to-sqlgridview

How to make GridView empty?


I have a GridView and am displaying results by search button. For the first search it works fine, but when I click on second search, even if that search result does not exist, the old data is still displayed.

How can I make the GridView empty if there is no result found?

I used LINQ to SQL concept to display the search results.


Solution

  • You have to assign null as DataSource and then rebind the gridview e.g.

    yourGridViewId.DataSource = null;
    yourGridViewId.DataBind();