Share via


FormView.EmptyDataTemplate 속성

정의

레코드가 들어 있지 않은 데이터 소스에 FormView 컨트롤이 바인딩될 때 렌더링되는 빈 데이터 행에 대한 사용자 정의 내용을 가져오거나 설정합니다.

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

속성 값

빈 데이터 행에 대한 사용자 지정 콘텐츠가 들어 있는 ITemplate입니다. 기본값은 null로, 이 속성이 설정되지 않았음을 나타냅니다.

특성

예제

다음 예제에서는 컨트롤이 레코드를 포함하지 않는 데이터 원본에 바인딩될 때 FormView 표시되는 빈 데이터 행에 대한 사용자 지정 템플릿을 정의하는 방법을 보여 줍니다.


<%@ 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>FormView EmptyDataTemplate Example</title>
</head>
<body>
    <form id="form1" runat="server">
        
      <h3>FormView EmptyDataTemplate Example</h3>
                       
      <asp:formview id="EmployeeFormView"
        datasourceid="EmployeeSource"
        allowpaging="true"
        datakeynames="EmployeeID" 
        runat="server">
        
        <EmptyDataRowStyle BackColor="Red"
          height="100"/> 
        
        <itemtemplate>
        
          <table>
            <tr>
              <td>
                <asp:image id="EmployeeImage"
                  imageurl='<%# Eval("PhotoPath") %>'
                  alternatetext='<%# Eval("LastName") %>' 
                  runat="server"/>
              </td>
              <td>
                <h3><%# Eval("FirstName") %> <%# Eval("LastName") %></h3>      
                <%# Eval("Title") %>        
              </td>
            </tr>
          </table>
        
        </itemtemplate>
          
        <emptydatatemplate>
          <table>
            <tr>
              <td>
                <asp:image id="NoDataImage"
                  imageurl="~/Images/NoDataImage.jpg" 
                  alternatetext="No image" 
                  runat="server"/>
              </td>
              <td>
                No records available.
              </td>
            </tr>
          </table>
        </emptydatatemplate>
          
        <pagersettings position="Bottom"
          mode="NextPrevious"/> 
                  
      </asp:formview>
          
      <!-- 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 select query for the following SqlDataSource     -->
      <!-- control is intentionally set to return no results    -->
      <!-- to demonstrate the empty data row.                   --> 
      <asp:sqldatasource id="EmployeeSource"
        selectcommand="Select [EmployeeID], [LastName], [FirstName], [Title], [PhotoPath] From [Employees] Where [EmployeeID]=1000"
        connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>" 
        runat="server"/>
            
    </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>FormView EmptyDataTemplate Example</title>
</head>
<body>
    <form id="form1" runat="server">
        
      <h3>FormView EmptyDataTemplate Example</h3>
                       
      <asp:formview id="EmployeeFormView"
        datasourceid="EmployeeSource"
        allowpaging="true"
        datakeynames="EmployeeID" 
        runat="server">
        
        <EmptyDataRowStyle BackColor="Red"
          height="100"/> 
        
        <itemtemplate>
        
          <table>
            <tr>
              <td>
                <asp:image id="EmployeeImage"
                  imageurl='<%# Eval("PhotoPath") %>'
                  alternatetext='<%# Eval("LastName") %>' 
                  runat="server"/>
              </td>
              <td>
                <h3><%# Eval("FirstName") %> <%# Eval("LastName") %></h3>      
                <%# Eval("Title") %>        
              </td>
            </tr>
          </table>
        
        </itemtemplate>
          
        <emptydatatemplate>
          <table>
            <tr>
              <td>
                <asp:image id="NoDataImage"
                  imageurl="~/Images/NoDataImage.jpg" 
                  alternatetext="No image" 
                  runat="server"/>
              </td>
              <td>
                No records available.
              </td>
            </tr>
          </table>
        </emptydatatemplate>
          
        <pagersettings position="Bottom"
          mode="NextPrevious"/> 
                  
      </asp:formview>
          
      <!-- 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 select query for the following SqlDataSource     -->
      <!-- control is intentionally set to return no results    -->
      <!-- to demonstrate the empty data row.                   --> 
      <asp:sqldatasource id="EmployeeSource"
        selectcommand="Select [EmployeeID], [LastName], [FirstName], [Title], [PhotoPath] From [Employees] Where [EmployeeID]=1000"
        connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>" 
        runat="server"/>
            
    </form>
  </body>
</html>

설명

컨트롤에 바인딩된 데이터 원본에 FormView 레코드가 없는 경우 빈 데이터 행이 컨트롤에 표시됩니다. 속성을 사용하여 빈 데이터 행에 대한 사용자 지정 UI(사용자 인터페이스)를 정의할 EmptyDataTemplate 수 있습니다. 빈 데이터 행에 대한 사용자 지정 템플릿을 지정하려면 먼저 컨트롤의 여는 태그와 닫는 태그 사이에 태그를 FormView 배치 <EmptyDataTemplate> 합니다. 다음 태그와 닫는 사이 템플릿의 콘텐츠를 나열할 수 있습니다 <EmptyDataTemplate> 태그입니다. 빈 데이터 행의 스타일을 제어하려면 속성을 사용합니다 EmptyDataRowStyle . 또는 이 속성 대신 속성을 설정하여 빈 데이터 행에 기본 제공 UI를 EmptyDataText 사용할 수 있습니다.

참고

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

적용 대상

추가 정보