DetailsView.CommandRowStyle 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得 TableItemStyle 物件的參考,這個物件可讓您設定 DetailsView 控制項中命令資料列的外觀。
public:
property System::Web::UI::WebControls::TableItemStyle ^ CommandRowStyle { System::Web::UI::WebControls::TableItemStyle ^ get(); };
[System.Web.UI.PersistenceMode(System.Web.UI.PersistenceMode.InnerProperty)]
public System.Web.UI.WebControls.TableItemStyle CommandRowStyle { get; }
[<System.Web.UI.PersistenceMode(System.Web.UI.PersistenceMode.InnerProperty)>]
member this.CommandRowStyle : System.Web.UI.WebControls.TableItemStyle
Public ReadOnly Property CommandRowStyle As TableItemStyle
屬性值
TableItemStyle 的參考,表示 DetailsView 控制項中命令資料列的樣式。
- 屬性
範例
下列程式碼範例示範如何使用 CommandRowStyle 屬性來指定 控制項中命令列的 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 CommandRowStyle Example</title>
</head>
<body>
<form id="Form1" runat="server">
<h3>DetailsView CommandRowStyle Example</h3>
<asp:detailsview id="CustomerDetailsView"
datasourceid="DetailsViewSource"
autogeneraterows="false"
datakeynames="CustomerID"
gridlines="Both"
allowpaging="true"
runat="server">
<headerstyle backcolor="Navy"
forecolor="White" />
<commandrowstyle backcolor="LightCyan"
font-names="Arial"
font-size="10"
font-bold="true"/>
<fields>
<asp:commandfield ButtonType="Link"
ShowEditButton="true"/>
<asp:boundfield datafield="CustomerID"
headertext="Customer ID"
readonly="true"/>
<asp:boundfield datafield="CompanyName"
headertext="Company Name"/>
<asp:boundfield datafield="Address"
headertext="Address"/>
<asp:boundfield datafield="City"
headertext="City"/>
<asp:boundfield datafield="PostalCode"
headertext="Postal Code"/>
<asp:boundfield datafield="Country"
headertext="Country"/>
</fields>
</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 CommandRowStyle Example</title>
</head>
<body>
<form id="Form1" runat="server">
<h3>DetailsView CommandRowStyle Example</h3>
<asp:detailsview id="CustomerDetailsView"
datasourceid="DetailsViewSource"
autogeneraterows="false"
datakeynames="CustomerID"
gridlines="Both"
allowpaging="true"
runat="server">
<headerstyle backcolor="Navy"
forecolor="White" />
<commandrowstyle backcolor="LightCyan"
font-names="Arial"
font-size="10"
font-bold="true"/>
<fields>
<asp:commandfield ButtonType="Link"
ShowEditButton="true"/>
<asp:boundfield datafield="CustomerID"
headertext="Customer ID"
readonly="true"/>
<asp:boundfield datafield="CompanyName"
headertext="Company Name"/>
<asp:boundfield datafield="Address"
headertext="Address"/>
<asp:boundfield datafield="City"
headertext="City"/>
<asp:boundfield datafield="PostalCode"
headertext="Postal Code"/>
<asp:boundfield datafield="Country"
headertext="Country"/>
</fields>
</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>
備註
CommandRowStyle使用 屬性來控制 控制項中 DetailsView 命令資料列的外觀。 命令資料列包含執行編輯、刪除和插入等作業的命令按鈕。 此屬性是唯讀的;不過,您可以設定其傳回之 TableItemStyle 物件的屬性。 屬性可以宣告方式設定在 表單 Property-Subproperty
中,其中 Subproperty
是 物件 (TableItemStyle 的屬性, CommandRowStyle-ForeColor
例如,) 。 屬性也可以在表單 Property.Subproperty
中以程式設計方式設定,例如, CommandRowStyle.ForeColor
) (。 一般設定通常包含自訂背景色彩、前景色彩和字型屬性。