ListView.EmptyItemTemplate Właściwość

Definicja

Pobiera lub ustawia zawartość zdefiniowaną przez użytkownika dla pustego elementu renderowanego w kontrolce ListView , gdy nie ma więcej elementów danych do wyświetlenia w ostatnim wierszu bieżącej strony danych.

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

Wartość właściwości

ITemplate

Obiekt, który zawiera zawartość niestandardową dla pustego elementu. Wartość domyślna to null, która wskazuje, że ta właściwość nie jest ustawiona.

Atrybuty

Przykłady

W poniższym przykładzie pokazano, jak zdefiniować szablon niestandardowy dla pustego elementu.

<%@ 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>

Uwagi

Pusty element jest wyświetlany w kontrolce ListView , gdy nie ma więcej elementów danych do wyświetlenia w ostatniej grupie bieżącej strony. Taka sytuacja może wystąpić tylko wtedy, gdy GroupItemCount jest ustawiona na wartość większą niż 1. Na przykład w kontrolce ListView właściwość może być ustawiona na 5, GroupItemCount a łączna liczba elementów zwróconych ze źródła danych wynosi 8. W takim przypadku ostatni wiersz danych będzie zawierać trzy elementy zdefiniowane przez ItemTemplate szablon i dwa elementy zdefiniowane przez EmptyItemTemplate szablon.

Możesz zdefiniować niestandardowy interfejs użytkownika (UI) dla pustego elementu przy użyciu EmptyItemTemplate właściwości . Aby deklaratywnie określić szablon niestandardowy dla pustego elementu, dodaj EmptyItemTemplate element wewnątrz kontrolki ListView . Następnie możesz dodać zawartość szablonu do EmptyItemTemplate elementu .

Dotyczy

Zobacz też