Export (0) Print
Expand All
Expand Minimize

ListView.EmptyItemTemplate Property

Gets or sets the user-defined content for the empty item that is rendered in a ListView control when there are no more data items to display in the last row of the current data page.

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

[BrowsableAttribute(false)]
[PersistenceModeAttribute(PersistenceMode.InnerProperty)]
[TemplateContainerAttribute(typeof(ListViewItem))]
public virtual ITemplate EmptyItemTemplate { get; set; }
<asp:ListView>
	<EmptyItemTemplate>ITemplate</EmptyItemTemplate>
</asp:ListView>

Property Value

Type: System.Web.UI.ITemplate
An object that contains the custom content for the empty item. The default is null, which indicates that this property is not set.

The empty item is displayed in a ListView control when there are no more data items to display in the last group of the current page. This can occur only if GroupItemCount is set to a value greater than 1. For example, in a ListView control, the GroupItemCount property might be set to 5 and the total number of items returned from the data source is 8. In that case, the last row of data will contain three items defined by the ItemTemplate template and two items defined by the EmptyItemTemplate template.

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

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

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

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

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head id="Head1" runat="server">
    <title>ListView EmptyItemTemplate Example</title>
  </head>
  <body>
    <form id="form1" runat="server">

      <h3>ListView EmptyItemTemplate Example</h3>

      <asp:ListView ID="ContactsListView" 
        DataSourceID="ContactsDataSource"
        GroupItemCount="4"
        runat="server">
        <LayoutTemplate>
          <table runat="server" id="tblProducts">
            <tr runat="server" id="groupPlaceholder" />
          </table>
         </LayoutTemplate>
         <GroupTemplate>
            <tr runat="server" id="ProductsRow" align="center">
              <td runat="server" id="itemPlaceholder" />
            </tr>
         </GroupTemplate>
         <ItemTemplate>
            <td runat="server">
              <asp:Label ID="FirstNameLabel" runat="Server" Text='<%#Eval("FirstName") %>' /><br />
              <asp:Label ID="LastNameLabel" runat="Server" Text='<%#Eval("LastName") %>' />
            </td>
         </ItemTemplate>
         <ItemSeparatorTemplate>
            <td runat="server" style="border-right: 1px solid #ccc">&nbsp;</td>
         </ItemSeparatorTemplate>
         <GroupSeparatorTemplate>
            <tr runat="server">
              <td colspan="7"><hr /></td>
            </tr>
         </GroupSeparatorTemplate>
         <EmptyItemTemplate>
            <td runat="server">***</td>
         </EmptyItemTemplate>
      </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 less results  -->
      <!-- to demonstrate the empty item template               -->       
      <asp:SqlDataSource ID="ContactsDataSource" runat="server" 
        ConnectionString="<%$ ConnectionStrings:AdventureWorks_DataConnectionString %>"
        SelectCommand="SELECT [ContactID], [FirstName], [LastName] 
            FROM Person.Contact 
            WHERE [ContactID]<10">
      </asp:SqlDataSource>

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

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

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

Show:
© 2014 Microsoft