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

빈 데이터 행에 대한 사용자 지정 콘텐츠가 들어 있는 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 . 또는 이 속성 대신 속성을 설정하여 빈 데이터 행에 기본 제공 UI를 EmptyDataText 사용할 수 있습니다.

빈 데이터 템플릿에서 선언하는 컨트롤에 프로그래밍 방식으로 액세스하는 방법에 대한 자세한 내용은 방법: ID별 액세스 서버 컨트롤을 참조하세요.

참고

모두를 EmptyDataTextEmptyDataTemplate 속성을 설정 합니다 EmptyDataTemplate 속성이 우선 합니다.

적용 대상

추가 정보