Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
.NET Framework 3.5
ListView Class
 EmptyDataTemplate Property
.NET Framework Class Library
ListView..::.EmptyDataTemplate Property

Updated: November 2007

Gets or sets the user-defined content for the empty template that is rendered when a ListView control is bound to a data source that does not contain any records.

Namespace:  System.Web.UI.WebControls
Assembly:  System.Web.Extensions (in System.Web.Extensions.dll)

Visual Basic (Declaration)
<BrowsableAttribute(False)> _
<PersistenceModeAttribute(PersistenceMode.InnerProperty)> _
<TemplateContainerAttribute(GetType(ListView))> _
Public Overridable Property EmptyDataTemplate As ITemplate
Visual Basic (Usage)
Dim instance As ListView
Dim value As ITemplate

value = instance.EmptyDataTemplate

instance.EmptyDataTemplate = value
C#
[BrowsableAttribute(false)]
[PersistenceModeAttribute(PersistenceMode.InnerProperty)]
[TemplateContainerAttribute(typeof(ListView))]
public virtual ITemplate EmptyDataTemplate { get; set; }
Visual C++
[BrowsableAttribute(false)]
[PersistenceModeAttribute(PersistenceMode::InnerProperty)]
[TemplateContainerAttribute(typeof(ListView))]
public:
virtual property ITemplate^ EmptyDataTemplate {
    ITemplate^ get ();
    void set (ITemplate^ value);
}
J#
/** @property */
/** @attribute BrowsableAttribute(false) */
/** @attribute PersistenceModeAttribute(PersistenceMode.InnerProperty) */
/** @attribute TemplateContainerAttribute(ListView) */
public ITemplate get_EmptyDataTemplate()
/** @property */
/** @attribute BrowsableAttribute(false) */
/** @attribute PersistenceModeAttribute(PersistenceMode.InnerProperty) */
/** @attribute TemplateContainerAttribute(ListView) */
public  void set_EmptyDataTemplate(ITemplate value)
JScript
public function get EmptyDataTemplate () : ITemplate
public function set EmptyDataTemplate (value : ITemplate)
ASP.NET
<asp:ListView>
    <EmptyDataTemplate>ITemplate</EmptyDataTemplate>
</asp:ListView>

Property Value

Type: System.Web.UI..::.ITemplate

An object that contains the custom content for the empty template. The default is nullNothingnullptra null reference (Nothing in Visual Basic), which indicates that this property is not set.

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.

Visual Basic
<%@ Page language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html  >
  <head id="Head1" runat="server">
    <title>ListView EmptyDataTemplate Example</title>
    <style type="text/css">
        .emptyTable { background-color:Aqua; }
    </style>
  </head>
  <body>
    <form id="form1" runat="server">

      <h3>ListView EmptyDataTemplate Example</h3>

      <asp:ListView ID="ContactsListView" 
        DataSourceID="ContactsDataSource" 
        runat="server">
        <LayoutTemplate>
          <table runat="server" id="tblProducts">
            <tr runat="server" id="itemPlaceholder" />
          </table>
         </LayoutTemplate>
         <ItemTemplate>
            <tr runat="server">
              <td>
                <asp:Label ID="FirstNameLabel" runat="Server" Text='<%#Eval("FirstName") %>' />
              </td>
              <td>
                <asp:Label ID="LastNameLabel" runat="Server" Text='<%#Eval("LastName") %>' />
              </td>
            </tr>
          </ItemTemplate>
          <EmptyDataTemplate>
              <table class="emptyTable" cellpadding="5" cellspacing="5">
                <tr>
                  <td>
                    <asp:Image ID="NoDataImage"
                      ImageUrl="~/Images/NoDataImage.jpg" 
                      runat="server"/>
                  </td>
                  <td>
                    No records available.
                  </td>
                </tr>
              </table>
          </EmptyDataTemplate>
      </asp:ListView>

      <!-- This example uses Microsoft SQL Server and connects      -->
      <!-- to the AdventureWorks sample database. Use an ASP.NET    -->
      <!-- expression to retrieve the connection string value       -->
      <!-- from the Web.config file.                                -->

      <!-- The select query for the following SqlDataSource     -->
      <!-- control is intentionally set to return no results    -->
      <!-- to demonstrate the empty data template               -->       
      <asp:SqlDataSource ID="ContactsDataSource" runat="server" 
            ConnectionString="<%$ ConnectionStrings:AdventureWorks_DataConnectionString %>"
            SelectCommand="SELECT [ContactID], [FirstName], [LastName] 
              FROM Person.Contact WHERE [ContactID]=1000">
      </asp:SqlDataSource>

    </form>
  </body>
</html>

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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html  >
  <head id="Head1" runat="server">
    <title>ListView EmptyDataTemplate Example</title>
    <style type="text/css">
        .emptyTable { background-color:Aqua; }
    </style>
  </head>
  <body>
    <form id="form1" runat="server">

      <h3>ListView EmptyDataTemplate Example</h3>

      <asp:ListView ID="ContactsListView" 
        DataSourceID="ContactsDataSource" 
        runat="server">
        <LayoutTemplate>
          <table runat="server" id="tblProducts">
            <tr runat="server" id="itemPlaceholder" />
          </table>
         </LayoutTemplate>
         <ItemTemplate>
            <tr runat="server">
              <td>
                <asp:Label ID="FirstNameLabel" runat="Server" Text='<%#Eval("FirstName") %>' />
              </td>
              <td>
                <asp:Label ID="LastNameLabel" runat="Server" Text='<%#Eval("LastName") %>' />
              </td>
            </tr>
          </ItemTemplate>
          <EmptyDataTemplate>
              <table class="emptyTable" cellpadding="5" cellspacing="5">
                <tr>
                  <td>
                    <asp:Image ID="NoDataImage"
                      ImageUrl="~/Images/NoDataImage.jpg" 
                      runat="server"/>
                  </td>
                  <td>
                    No records available.
                  </td>
                </tr>
              </table>
          </EmptyDataTemplate>
      </asp:ListView>

      <!-- This example uses Microsoft SQL Server and connects      -->
      <!-- to the AdventureWorks sample database. Use an ASP.NET    -->
      <!-- expression to retrieve the connection string value       -->
      <!-- from the Web.config file.                                -->

      <!-- The select query for the following SqlDataSource     -->
      <!-- control is intentionally set to return no results    -->
      <!-- to demonstrate the empty data template               -->       
      <asp:SqlDataSource ID="ContactsDataSource" runat="server" 
            ConnectionString="<%$ ConnectionStrings:AdventureWorks_DataConnectionString %>"
            SelectCommand="SELECT [ContactID], [FirstName], [LastName] 
              FROM Person.Contact WHERE [ContactID]=1000">
      </asp:SqlDataSource>

    </form>
  </body>
</html>

Windows Vista, Windows XP SP2, Windows Server 2003

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2008 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker