DetailsView.EmptyDataTemplate プロパティ

定義

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

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.DetailsView))]
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.DetailsView))>]
member this.EmptyDataTemplate : System.Web.UI.ITemplate with get, set
Public Overridable Property EmptyDataTemplate As ITemplate

プロパティ値

ITemplate

空のデータ行用のカスタム コンテンツを含んだ ITemplate。 既定値は null で、このプロパティが設定されていないことを示します。

属性

次のコード例は、プロパティを使用してカスタムの空の EmptyDataTemplate データ行を作成する方法を示しています。


<%@ 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 runat="server">
    <title>DetailsView EmptyDataTemplate Example</title>
</head>
<body>
    <form id="form1" runat="server">
        
      <h3>DetailsView EmptyDataTemplate Example</h3>
                
        <asp:detailsview id="StoresDetailView"
          datasourceid="StoresDetailsSqlDataSource"
          autogeneraterows="true" 
          EmptyDataText="No records." 
          runat="server">
               
          <emptydatarowstyle backcolor="Navy"
            forecolor="Red"/>
            
          <emptydatatemplate>
          
            <table width="100%">
            
              <tr>
                <td>
                  <asp:Image id="NoRecordsImage"
                    AlternateText='No records' 
                    imageurl="~\images\NoRecords.jpg"
                    runat="server"/> 
                </td>
                <td>
                  <asp:Label id="NoRecordsMessageLabel"
                    forecolor="Red"
                    text="No Records."
                    runat="server"/> 
                </td>
              </tr>
            
            </table>
          
          </emptydatatemplate> 
                    
        </asp:detailsview>
            
        <!-- This example uses Microsoft SQL Server and connects -->
        <!-- to the Pubs sample database.                        -->
        
        <!-- The select query of the following SqlDataSource     -->
        <!-- control has been intentionally set to return no     --> 
        <!-- results to demonstrate the empty data row.          -->      
        <asp:sqldatasource id="StoresDetailsSqlDataSource"  
          selectcommand="SELECT [stor_id], [stor_name], [stor_address], [city], [state], [zip] FROM [stores] WHERE [state]='FL'"
          connectionstring="server=localhost;database=pubs;integrated security=SSPI"
          runat="server">
        </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 runat="server">
    <title>DetailsView EmptyDataTemplate Example</title>
</head>
<body>
    <form id="form1" runat="server">
        
      <h3>DetailsView EmptyDataTemplate Example</h3>
                
        <asp:detailsview id="StoresDetailView"
          datasourceid="StoresDetailsSqlDataSource"
          autogeneraterows="true" 
          EmptyDataText="No records." 
          runat="server">
               
          <emptydatarowstyle backcolor="Navy"
            forecolor="Red"/>
            
          <emptydatatemplate>
          
            <table width="100%">
            
              <tr>
                <td>
                  <asp:Image id="NoRecordsImage"
                    AlternateText='No Records' 
                    imageurl="~\images\NoRecords.jpg"
                    runat="server"/> 
                </td>
                <td>
                  <asp:Label id="NoRecordsMessageLabel"
                    forecolor="Red"
                    text="No records."
                    runat="server"/> 
                </td>
              </tr>
            
            </table>
          
          </emptydatatemplate> 
                    
        </asp:detailsview>
            
        <!-- This example uses Microsoft SQL Server and connects -->
        <!-- to the Pubs sample database.                        -->
        
        <!-- The select query of the following SqlDataSource     -->
        <!-- control has been intentionally set to return no     --> 
        <!-- results to demonstrate the empty data row.          -->      
        <asp:sqldatasource id="StoresDetailsSqlDataSource"  
          selectcommand="SELECT [stor_id], [stor_name], [stor_address], [city], [state], [zip] FROM [stores] WHERE [state]='FL'"
          connectionstring="server=localhost;database=pubs;integrated security=SSPI"
          runat="server">
        </asp:sqldatasource>
            
      </form>
  </body>
</html>

注釈

コントロールにバインドされているデータ ソースに DetailsView レコードが含まれていない場合、空のデータ行がコントロールに表示されます。 このプロパティを使用して、空のデータ行に独自のカスタム ユーザー インターフェイス (UI) を EmptyDataTemplate 定義できます。 null 行のカスタム テンプレートを指定するには、最初にコントロールの開始タグと終了タグの間にタグをDetailsView配置<EmptyDataTemplate>します。 その後、開始タグと終了 <EmptyDataTemplate> タグの間のテンプレートの内容を一覧表示できます。 空のデータ行のスタイルを制御するには、プロパティを EmptyDataRowStyle 使用します。 または、このプロパティの代わりにプロパティを設定 EmptyDataText することで、空のデータ行に組み込みの UI を使用することもできます。

注意

プロパティとEmptyDataTemplateプロパティの両方がEmptyDataText設定されている場合は、プロパティがEmptyDataTemplate優先されます。

適用対象

こちらもご覧ください