Search code examples
asp.netlistviewdropdownemptydatatemplate

asp EmptyDataTemplate not always working


I have a listview which bind data on selected country value dropdownlist from sharepoint diffrent lists by country, sometimes the list is empty so I add :

<EmptyDataTemplate>
<div>No records found. </div>
</EmptyDataTemplate>

Scenario:

  1. from Dropdownlist(countries list), I choose an empty list (country 1), it displays "No records found"

  2. from Dropdownlist, I choose a non empty list (country 2), it displays the records

  3. but from Dropdownlist, when I want to get back to (country 1) which is empty, it still displays data from (country 2)
  4. from Dropdownlist, When I choose a non empty (country 3), it displays the records

So I don't know why in step 3 when I turn back to (country 1) or even if I choose another empty country list it still display the records from non empty list. Help Please.


Solution

  • You need to rebind the gridview to an empty data source when the country is empty.

    if(countryHasNoRecords)
    {
       gvMyGridView.DataSource = null;
       gvMyGridView.DataBind();
    }