DetailsView.RowStyle 屬性

定義

取得 TableItemStyle 物件的參考,這個物件可讓您設定 DetailsView 控制項中資料列的外觀。

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

屬性值

TableItemStyle

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

屬性

範例

下列程式碼範例示範如何使用 RowStyle 屬性來指定 控制項中資料列的 DetailsView 字型和樣式設定。

<%@ 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>DetailsView RowStyle and AlternatingRowStyle Example</title>
</head>
<body>
    <form id="Form1" runat="server">
        
      <h3>DetailsView RowStyle and AlternatingRowStyle Example</h3>
                
        <asp:detailsview id="CustomersView"
          datasourceid="Customers"
          autogeneraterows="true"
          allowpaging="true" 
          runat="server">
               
          <headerstyle backcolor="Navy"
            forecolor="White"/>
            
          <RowStyle BackColor="LightGray"
            ForeColor="Blue"
            Font-Names="Arial"
            Font-Size="10"
            Font-Italic="true"/>
            
          <AlternatingRowStyle BackColor="White"
            ForeColor="Blue"
            Font-Names="Arial"
            Font-Size="10"
            Font-Italic="true"/>
                    
        </asp:detailsview>
            
        <!-- This example uses Microsoft SQL Server and connects -->
        <!-- to the Northwind sample database. -->           
        <asp:SqlDataSource ID="Customers" runat="server" 
          ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
          SelectCommand="SELECT [CompanyName], [ContactName], [CustomerID], [Phone] FROM [Customers]">
        </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>DetailsView RowStyle and AlternatingRowStyle Example</title>
</head>
<body>
    <form id="Form1" runat="server">
        
      <h3>DetailsView RowStyle and AlternatingRowStyle Example</h3>
                
        <asp:detailsview id="CustomersView"
          datasourceid="Customers"
          autogeneraterows="true"
          allowpaging="true" 
          runat="server">
               
          <headerstyle backcolor="Navy"
            forecolor="White"/>
            
          <RowStyle BackColor="LightGray"
            ForeColor="Blue"
            Font-Names="Arial"
            Font-Size="10"
            Font-Italic="true"/>
            
          <AlternatingRowStyle BackColor="White"
            ForeColor="Blue"
            Font-Names="Arial"
            Font-Size="10"
            Font-Italic="true"/>
                    
        </asp:detailsview>
            
        <!-- This example uses Microsoft SQL Server and connects -->
        <!-- to the Northwind sample database. -->           
        <asp:SqlDataSource ID="Customers" runat="server" 
          ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
          SelectCommand="SELECT [CompanyName], [ContactName], [CustomerID], [Phone] FROM [Customers]">
        </asp:SqlDataSource>
            
      </form>
  </body>
</html>

備註

RowStyle使用 屬性來控制 控制項中 DetailsView 資料列的外觀。 AlternatingRowStyle同時設定 屬性時,資料列會顯示在設定與 AlternatingRowStyle 設定之間 RowStyle 交替。 此屬性是唯讀的;不過,您可以設定其傳回之 TableItemStyle 物件的屬性。 屬性可以宣告方式設定在 表單 Property-Subproperty 中,其中 Subproperty 是 物件 (TableItemStyle 的屬性, RowStyle-ForeColor 例如,) 。 屬性也可以在表單 Property.Subproperty 中以程式設計方式設定,例如, RowStyle.ForeColor) (。 一般設定通常包含自訂背景色彩、前景色彩和字型屬性。

適用於

另請參閱