DetailsView.InsertRowStyle 屬性

定義

取得 TableItemStyle 物件的參考,這個物件可讓您在 DetailsView 控制項處於插入模式時,設定 DetailsView 控制項中資料列的外觀。

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

屬性值

TableItemStyle 的參考,表示當 DetailsView 控制項處於插入模式時,DetailsView 控制項中資料列的樣式。

屬性

範例

下列程式碼範例示範如何在控制項處於插入模式時 DetailsView ,使用 InsertRowStyle 屬性來指定資料列的字型和樣式設定。


<%@ 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 InsertRowStyle Example</title>
</head>
<body>
    <form id="Form1" runat="server">
        
      <h3>DetailsView InsertRowStyle Example</h3>
                
        <asp:detailsview id="CustomerDetailView"
          datasourceid="DetailsViewSource"
          datakeynames="CustomerID"
          autogenerateinsertbutton="true"  
          autogeneraterows="true"
          allowpaging="true"  
          runat="server">
               
          <fieldheaderstyle backcolor="Navy"
            forecolor="White"/>
            
          <insertrowstyle backcolor="Yellow"/>
                    
        </asp:detailsview>
        
        <!-- 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="DetailsViewSource" runat="server" 
          ConnectionString=
            "<%$ ConnectionStrings:NorthWindConnectionString%>"
            InsertCommand="INSERT INTO [Customers]([CustomerID], [CompanyName], [Address], [City], [PostalCode], [Country]) VALUES (@CustomerID, @CompanyName, @Address, @City, @PostalCode, @Country)"
          SelectCommand="Select [CustomerID], [CompanyName], 
            [Address], [City], [PostalCode], [Country] 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 InsertRowStyle Example</title>
</head>
<body>
    <form id="Form1" runat="server">
        
      <h3>DetailsView InsertRowStyle Example</h3>
                
        <asp:detailsview id="CustomerDetailView"
          datasourceid="DetailsViewSource"
          datakeynames="CustomerID"
          autogenerateinsertbutton="true"  
          autogeneraterows="true"
          allowpaging="true"  
          runat="server">
               
          <fieldheaderstyle backcolor="Navy"
            forecolor="White"/>
            
          <insertrowstyle backcolor="Yellow"/>
                    
        </asp:detailsview>
        
        <!-- 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="DetailsViewSource" runat="server" 
          ConnectionString=
            "<%$ ConnectionStrings:NorthWindConnectionString%>"
            InsertCommand="INSERT INTO [Customers]([CustomerID], [CompanyName], [Address], [City], [PostalCode], [Country]) VALUES (@CustomerID, @CompanyName, @Address, @City, @PostalCode, @Country)"
          SelectCommand="Select [CustomerID], [CompanyName], 
            [Address], [City], [PostalCode], [Country] From 
            [Customers]">
        </asp:SqlDataSource>
    </form>
  </body>
</html>

備註

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

適用於

另請參閱