GridView.EmptyDataTemplate プロパティ

定義

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

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

プロパティ値

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

属性

次の例では、レコードを含まないデータ ソースにコントロールがバインドされたときに GridView 表示される空のデータ行のカスタム テンプレートを定義する方法を示します。


<%@ 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>GridView EmptyDataTemplate Example</title>
</head>
<body>
    <form id="form1" runat="server">
        
      <h3>GridView EmptyDataTemplate Example</h3>

      <asp:gridview id="CustomersGridView" 
        datasourceid="CustomersSqlDataSource" 
        autogeneratecolumns="true"
        runat="server">
        
        <emptydatarowstyle backcolor="LightBlue"
          forecolor="Red"/>
                    
        <emptydatatemplate>
                
          <asp:image id="NoDataImage"
            imageurl="~/images/Image.jpg"
            alternatetext="No Image" 
            runat="server"/>
                        
            No Data Found.  
                
        </emptydatatemplate> 
                
      </asp:gridview>
            
      <!-- This example uses Microsoft SQL Server and connects  -->
      <!-- to the Northwind sample database. Use an ASP.NET     -->
      <!-- expression to retrieve the connection string value   -->
      <!-- from the Web.config file. The following query        -->
      <!-- returns an empty data source to demonstrate the      -->
      <!-- empty row.                                           -->
      <asp:sqldatasource id="CustomersSqlDataSource"  
        selectcommand="Select [CustomerID], [CompanyName], [Address], [City], [PostalCode], [Country] From [Customers] Where CustomerID='NoID'"
        connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>"
        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>GridView EmptyDataTemplate Example</title>
</head>
<body>
    <form id="form1" runat="server">
        
      <h3>GridView EmptyDataTemplate Example</h3>

      <asp:gridview id="CustomersGridView" 
        datasourceid="CustomersSqlDataSource" 
        autogeneratecolumns="true"
        runat="server">
        
        <emptydatarowstyle backcolor="LightBlue"
          forecolor="Red"/>
                    
        <emptydatatemplate>
                
          <asp:image id="NoDataImage"
            imageurl="~/images/Image.jpg"
            alternatetext="No Image" 
            runat="server"/>
                        
            No Data Found.  
                
        </emptydatatemplate> 
                
      </asp:gridview>
            
      <!-- This example uses Microsoft SQL Server and connects  -->
      <!-- to the Northwind sample database. Use an ASP.NET     -->
      <!-- expression to retrieve the connection string value   -->
      <!-- from the Web.config file. The following query        -->
      <!-- returns an empty data source to demonstrate the      -->
      <!-- empty row.                                           -->
      <asp:sqldatasource id="CustomersSqlDataSource"  
        selectcommand="Select [CustomerID], [CompanyName], [Address], [City], [PostalCode], [Country] From [Customers] Where CustomerID='NoID'"
        connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>"
        runat="server">
      </asp:sqldatasource>
            
    </form>
  </body>
</html>

注釈

コントロールにバインドされているデータ ソースに GridView レコードが含まれていない場合、空のデータ行がコントロールに表示されます。 プロパティを使用して、空のデータ行に独自のカスタム ユーザー インターフェイス (UI) を EmptyDataTemplate 定義できます。

空のデータ行にカスタム テンプレートを指定するには、まず、コントロールの開始タグと終了タグの間にタグをGridView配置<EmptyDataTemplate>します。 その後、開始タグと終了 <EmptyDataTemplate> タグの間のテンプレートの内容を一覧表示できます。 空のデータ行のスタイルを制御するには、 プロパティを EmptyDataRowStyle 使用します。 または、このプロパティの代わりに プロパティを設定 EmptyDataText することで、空のデータ行に組み込みの UI を使用することもできます。

空のデータ テンプレートで宣言したコントロールにプログラムでアクセスする方法の詳細については、「 How to: Access Server Controls by ID」を参照してください。

注意

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

適用対象

こちらもご覧ください