FormView.EmptyDataRowStyle 属性

定义

获取一个对 TableItemStyle 对象的引用,使用该对象可以设置在绑定到 FormView 控件的数据源不包含任何记录时所显示的空数据行的外观。Gets a reference to the TableItemStyle object that allows you to set the appearance of the empty data row displayed when the data source bound to a FormView control does not contain any records.

public:
 property System::Web::UI::WebControls::TableItemStyle ^ EmptyDataRowStyle { System::Web::UI::WebControls::TableItemStyle ^ get(); };
[System.Web.UI.PersistenceMode(System.Web.UI.PersistenceMode.InnerProperty)]
public System.Web.UI.WebControls.TableItemStyle EmptyDataRowStyle { get; }
[<System.Web.UI.PersistenceMode(System.Web.UI.PersistenceMode.InnerProperty)>]
member this.EmptyDataRowStyle : System.Web.UI.WebControls.TableItemStyle
Public ReadOnly Property EmptyDataRowStyle As TableItemStyle

属性值

TableItemStyle

一个对 TableItemStyle 的引用,使用该对象可以设置空数据行的外观。A reference to the TableItemStyle that allows you to set the appearance of the empty data row.

属性

示例

下面的示例演示如何使用 EmptyDataRowStyle 属性为 FormView 控件绑定到不包含任何记录的数据源时所显示的空数据行指定自定义样式。The following example demonstrates how to use the EmptyDataRowStyle property to specify a custom style for the empty data row displayed when a FormView control is bound to a data source that does not contain any records.


<%@ 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 EmptyDataText Example</title>
</head>
<body>
    <form id="form1" runat="server">
        
      <h3>FormView EmptyDataText Example</h3>
                       
      <asp:formview id="EmployeeFormView"
        datasourceid="EmployeeSource"
        allowpaging="true"
        datakeynames="EmployeeID"
        emptydatatext="No records available." 
        runat="server">
        
        <EmptyDataRowStyle BackColor="Red"
          forecolor="White"
          font-size="14"
          font-italic="true" 
          height="100"/> 
        
        <itemtemplate>
        
          <table>
            <tr>
              <td>
                <asp:image id="EmployeeImage"
                  imageurl='<%# Eval("PhotoPath") %>'
                  alternatetext='<%# Eval("LastName") %>' 
                  runat="server"/>
              </td>
              <td>
                <h3><%# Eval("FirstName") %>&nbsp;<%# Eval("LastName") %></h3>      
                <%# Eval("Title") %>        
              </td>
            </tr>
          </table>
        
        </itemtemplate>
          
        <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 EmptyDataText Example</title>
</head>
<body>
    <form id="form1" runat="server">
        
      <h3>FormView EmptyDataText Example</h3>
                       
      <asp:formview id="EmployeeFormView"
        datasourceid="EmployeeSource"
        allowpaging="true"
        datakeynames="EmployeeID"
        emptydatatext="No records available." 
        runat="server">
        
        <EmptyDataRowStyle BackColor="Red"
          forecolor="White"
          font-size="14"
          font-italic="true" 
          height="100"/> 
        
        <itemtemplate>
        
          <table>
            <tr>
              <td>
                <asp:image id="EmployeeImage"
                  imageurl='<%# Eval("PhotoPath") %>'
                  alternatetext='<%# Eval("LastName") %>' 
                  runat="server"/>
              </td>
              <td>
                <h3><%# Eval("FirstName") %>&nbsp;<%# Eval("LastName") %></h3>      
                <%# Eval("Title") %>        
              </td>
            </tr>
          </table>
        
        </itemtemplate>
          
        <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>

注解

使用 EmptyDataRowStyle 属性可控制控件中的空数据行的外观 FormViewUse the EmptyDataRowStyle property to control the appearance of the empty data row in a FormView control. 当绑定到控件的数据源不包含任何记录时,将显示空数据行。The empty data row is displayed when the data source that is bound to the control does not contain any records. 此属性是只读的;但是,您可以设置 TableItemStyle 它返回的对象的属性。This property is read-only; however, you can set the properties of the TableItemStyle object it returns. 可以使用下列方法之一以声明方式设置属性:The properties can be set declaratively using one of the following methods:

  • 在窗体的控件的开始标记中放置一个属性 FormView Property-Subproperty ,其中 Subproperty 是对象的属性 TableItemStyle (例如 EmptyDataRowStyle-ForeColor) 。Place an attribute in the opening tag of the FormView control in the form Property-Subproperty, where Subproperty is a property of the TableItemStyle object (for example, EmptyDataRowStyle-ForeColor).

  • <EmptyDataRowStyle>在控件的开始标记和结束标记之间嵌套元素 FormViewNest an <EmptyDataRowStyle> element between the opening and closing tags of the FormView control.

还可以以编程方式设置属性 Property.Subproperty , (例如 EmptyDataRowStyle.ForeColor) 。The properties can also be set programmatically in the form Property.Subproperty (for example, EmptyDataRowStyle.ForeColor). 常见设置通常包括自定义背景色、前景色和字体属性。Common settings usually include a custom background color, foreground color, and font properties.

适用于

另请参阅