Share via


ListView.EmptyDataTemplate Proprietà

Definizione

Ottiene o imposta il contenuto definito dall'utente per il modello vuoto di cui viene eseguito il rendering quando un controllo ListView è associato a un'origine dati che non contiene record.

public:
 virtual property System::Web::UI::ITemplate ^ EmptyDataTemplate { 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.ListView))]
public virtual System.Web.UI.ITemplate EmptyDataTemplate { get; set; }
[<System.ComponentModel.Browsable(false)>]
[<System.Web.UI.PersistenceMode(System.Web.UI.PersistenceMode.InnerProperty)>]
[<System.Web.UI.TemplateContainer(typeof(System.Web.UI.WebControls.ListView))>]
member this.EmptyDataTemplate : System.Web.UI.ITemplate with get, set
Public Overridable Property EmptyDataTemplate As ITemplate

Valore della proprietà

ITemplate

Oggetto che include il contenuto personalizzato per il modello vuoto. Il valore predefinito è null, che indica che la proprietà non è impostata.

Attributi

Esempio

Nell'esempio seguente viene illustrato come definire un modello personalizzato per il modello vuoto.

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

Commenti

Il modello vuoto viene visualizzato in un ListView controllo quando l'origine dati associata al controllo non contiene record e la InsertItemPosition proprietà è impostata su InsertItemPosition.None. Il rendering del modello viene eseguito invece del LayoutTemplate modello. Se la InsertItemPosition proprietà è impostata su un valore diverso da InsertItemPosition.None, il modello non viene eseguito il EmptyDataTemplate rendering.

È possibile definire un'interfaccia utente personalizzata per il modello vuoto usando la EmptyDataTemplate proprietà . Per specificare un modello personalizzato dichiarativo per il modello vuoto, aggiungere ed EmptyDataTemplate elemento all'interno del ListView controllo. È quindi possibile aggiungere il contenuto del modello all'elemento EmptyDataTemplate .

Si applica a

Vedi anche