ListView.EmptyItemTemplate Свойство

Определение

Возвращает или задает пользовательское содержимое для пустого элемента, который преобразовывается для просмотра в элементе управления ListView, когда в последней строке текущей страницы данных больше нет отображаемых элементов данных.

public:
 virtual property System::Web::UI::ITemplate ^ EmptyItemTemplate { System::Web::UI::ITemplate ^ get(); void set(System::Web::UI::ITemplate ^ value); };
[System.ComponentModel.Browsable(false)]
[System.Web.UI.PersistenceMode(System.Web.UI.PersistenceMode.InnerProperty)]
[System.Web.UI.TemplateContainer(typeof(System.Web.UI.WebControls.ListViewItem))]
public virtual System.Web.UI.ITemplate EmptyItemTemplate { get; set; }
[<System.ComponentModel.Browsable(false)>]
[<System.Web.UI.PersistenceMode(System.Web.UI.PersistenceMode.InnerProperty)>]
[<System.Web.UI.TemplateContainer(typeof(System.Web.UI.WebControls.ListViewItem))>]
member this.EmptyItemTemplate : System.Web.UI.ITemplate with get, set
Public Overridable Property EmptyItemTemplate As ITemplate

Значение свойства

ITemplate

Объект с пользовательским содержимым для пустого элемента. Значение по умолчанию — "null", указывающее, что это свойство не задано.

Атрибуты

Примеры

В следующем примере показано, как определить пользовательский шаблон для пустого элемента.

<%@ 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>
<%@ Page language="VB" %>
    
<!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>

Комментарии

Пустой элемент отображается в элементе ListView управления, если в последней группе текущей страницы больше нет элементов данных. Это может произойти только в том случае, если GroupItemCount задано значение больше 1. Например, в элементе ListView управления свойство может иметь значение 5, GroupItemCount а общее количество элементов, возвращаемых из источника данных, равно 8. В этом случае последняя строка данных будет содержать три элемента, определенные шаблоном ItemTemplate , и два элемента, определенные шаблоном EmptyItemTemplate .

Вы можете определить пользовательский интерфейс для пустого элемента с помощью EmptyItemTemplate свойства. Чтобы указать настраиваемый шаблон декларативно для пустого элемента, добавьте EmptyItemTemplate элемент внутри ListView элемента управления. Затем вы можете добавить содержимое шаблона в EmptyItemTemplate элемент.

Применяется к

См. также раздел