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.
You have to assign null
as DataSource and then rebind the gridview e.g.
yourGridViewId.DataSource = null;
yourGridViewId.DataBind();
"emptydatatemplate" works better in my case:
<asp:Panel runat="server" ID="panelGrilla" CssClass="scrollable" Height="350px" ScrollBars="Vertical">
<asp:GridView ID="GridAcc" CssClass="cgrid" runat="server" AutoGenerateColumns="false" Width="100%">
<emptydatatemplate>No data found</emptydatatemplate>
<EmptyDataRowStyle HorizontalAlign="Center" />
</asp:GridView>
</asp:Panel>
精彩评论