Learning Resources
 

Advising users there’s no data with EmptyDataTemplate


 

The empty template is displayed in a ListView control when the data source that is bound to the control does not contain any records and the InsertItemPosition property is set to InsertItemPosition.None. The template is rendered instead of the LayoutTemplate template. If the InsertItemPosition property is set to a value other than InsertItemPosition.None, the EmptyDataTemplate template is not rendered.

You can define a custom user interface (UI) for the empty template by using the EmptyDataTemplate property. To specify a custom template declaratively for the empty template, add and EmptyDataTemplate element inside the ListView control. You can then add the contents of the template to the EmptyDataTemplate element.

The following example shows how to define a custom template for the empty template.

<%@ Page language="C#" %>

    "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


 
    ListView EmptyDataTemplate Example
   
 
 
   



     

ListView EmptyDataTemplate Example



              DataSourceID="ContactsDataSource"
        runat="server">
       
         
           
         

        

        
           
             
               
             
             
               
             
           
         

         
             
               
                 
                 
               
             

                                          ImageUrl="~/Images/NoDataImage.jpg"
                      runat="server"/>
                 

                    No records available.
                 

         

     


     
     
     
     

     
     
             
                  ConnectionString="<%$ ConnectionStrings:AdventureWorks_DataConnectionString %>"
            SelectCommand="SELECT [ContactID], [FirstName], [LastName]
              FROM Person.Contact WHERE [ContactID]=1000">