ListView.EmptyItemTemplate Propiedad

Definición

Obtiene o establece el contenido definido por el usuario para el elemento vacío que se representa en un control ListView cuando no hay ningún elemento de datos más que mostrar en la última fila de la página de datos actual.

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

Valor de propiedad

ITemplate

Objeto que incluye el contenido personalizado para el elemento vacío. El valor predeterminado es null, lo que indica que esta propiedad no se estableció.

Atributos

Ejemplos

En el ejemplo siguiente se muestra cómo definir una plantilla personalizada para el elemento vacío.

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

Comentarios

El elemento vacío se muestra en un ListView control cuando no hay más elementos de datos que mostrar en el último grupo de la página actual. Esto solo puede ocurrir si GroupItemCount se establece en un valor mayor que 1. Por ejemplo, en un ListView control, la GroupItemCount propiedad puede establecerse en 5 y el número total de elementos devueltos desde el origen de datos es 8. En ese caso, la última fila de datos contendrá tres elementos definidos por la ItemTemplate plantilla y dos elementos definidos por la EmptyItemTemplate plantilla.

Puede definir una interfaz de usuario personalizada (UI) para el elemento vacío mediante la EmptyItemTemplate propiedad . Para especificar una plantilla personalizada mediante declaración para el elemento vacío, agregue un EmptyItemTemplate elemento dentro del ListView control . A continuación, puede agregar el contenido de la plantilla al EmptyItemTemplate elemento .

Se aplica a

Consulte también