FormView.HeaderStyle 屬性

定義

取得 TableItemStyle 物件的參考,可以讓您設定 FormView 控制項中頁首資料列的外觀。

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

屬性值

TableItemStyle

TableItemStyle 的參考,表示 FormView 控制項中標頭資料列的樣式。

屬性

範例

下列範例示範如何使用 HeaderStyle 屬性來指定標頭資料列的自訂樣式。


<%@ 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 HeaderText Example</title>
</head>
<body>
    <form id="form1" runat="server">
        
      <h3>FormView HeaderText Example</h3>
                       
      <asp:formview id="EmployeeFormView"
        datasourceid="EmployeeSource"
        allowpaging="true" 
        datakeynames="EmployeeID"
        headertext="Employee Name" 
        runat="server">
        
        <headerstyle horizontalalign="Center"
          forecolor="White"
          backcolor="Blue"/>
           
        <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>
          
        <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.                            -->
      <asp:sqldatasource id="EmployeeSource"
        selectcommand="Select [EmployeeID], [LastName], [FirstName], [Title], [PhotoPath] From [Employees]"
        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 HeaderText Example</title>
</head>
<body>
    <form id="form1" runat="server">
        
      <h3>FormView HeaderText Example</h3>
                       
      <asp:formview id="EmployeeFormView"
        datasourceid="EmployeeSource"
        allowpaging="true" 
        datakeynames="EmployeeID"
        headertext="Employee Name" 
        runat="server">
        
        <headerstyle horizontalalign="Center"
          forecolor="White"
          backcolor="Blue"/>
           
        <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>
          
        <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.                            -->
      <asp:sqldatasource id="EmployeeSource"
        selectcommand="Select [EmployeeID], [LastName], [FirstName], [Title], [PhotoPath] From [Employees]"
        connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>" 
        runat="server"/>
            
    </form>
  </body>
</html>

備註

設定 或 HeaderTemplate 屬性時 HeaderText ,標頭資料列會顯示在控制項頂端 FormViewHeaderStyle使用 屬性來控制 控制項中 FormView 標頭資料列的外觀。 此屬性是唯讀的;不過,您可以設定它所傳回之 TableItemStyle 物件的屬性。 您可以使用下列其中一種方法,以宣告方式設定屬性:

  • 將屬性放在 控制項的 FormView 開頭標記中,其中 Subproperty 是 物件的屬性 TableItemStyle (例如, HeaderStyle-ForeColor Property-Subproperty) 。

  • 在控制項的開頭和結束記號 FormView 之間巢狀專案 <HeaderStyle>

屬性也可以在表單 Property.Subproperty 中以程式設計方式設定,例如 () HeaderStyle.ForeColor 。 一般設定通常包括自訂背景色彩、前景色彩和字型屬性。

適用於

另請參閱