ListView.EmptyDataTemplate プロパティ

定義

空のテンプレートに対するユーザー定義のコンテンツを取得または設定します。これは、レコードが格納されていないデータ ソースに ListView コントロールがバインドされている場合に表示されます。

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

プロパティ値

空のテンプレートのカスタム コンテンツが格納されたオブジェクト。 既定値は 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 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>

注釈

コントロールにバインドされているデータ ソースに ListView レコードが含まれていないときに、 プロパティが に設定されている場合、空の InsertItemPosition テンプレートがコントロールに InsertItemPosition.None表示されます。 テンプレートは、テンプレートの LayoutTemplate 代わりにレンダリングされます。 プロパティが 以外InsertItemPosition.NoneInsertItemPosition値に設定されている場合、EmptyDataTemplateテンプレートはレンダリングされません。

プロパティを使用して、空のテンプレートのカスタム ユーザー インターフェイス (UI) を EmptyDataTemplate 定義できます。 空のテンプレートに対して宣言的にカスタム テンプレートを指定するには、 コントロール内に および EmptyDataTemplate 要素を ListView 追加します。 その後、テンプレートの内容を 要素に EmptyDataTemplate 追加できます。

適用対象

こちらもご覧ください