DataControlField.ControlStyle 属性
定义
获取 DataControlField 对象所包含的任何 Web 服务器控件的样式。Gets the style of any Web server controls contained by the DataControlField object.
public:
property System::Web::UI::WebControls::Style ^ ControlStyle { System::Web::UI::WebControls::Style ^ get(); };
[System.Web.UI.PersistenceMode(System.Web.UI.PersistenceMode.InnerProperty)]
public System.Web.UI.WebControls.Style ControlStyle { get; }
[<System.Web.UI.PersistenceMode(System.Web.UI.PersistenceMode.InnerProperty)>]
member this.ControlStyle : System.Web.UI.WebControls.Style
Public ReadOnly Property ControlStyle As Style
属性值
一个 Style,控制字段所包含的 Web 服务器控件的外观。A Style that governs the appearance of Web server controls contained by the field.
- 属性
示例
下面的代码示例演示如何使用 BoundField 和 ButtonField 派生自的对象 DataControlField 来显示控件中的行 DetailsView 。The following code example demonstrates how to use BoundField and ButtonField objects, which are derived from DataControlField, to display rows in a DetailsView control. ControlStyle设置对象的属性 ButtonField ,并控制如何 LinkButton 显示字段中包含的控件。The ControlStyle property of the ButtonField object is set and governs how the LinkButton control contained by the field is displayed.
<%@ 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>ASP.NET Example</title>
</head>
<body>
<form id="form1" runat="server">
<asp:detailsview
id="DetailsView1"
runat="server"
allowpaging="True"
datasourceid="SqlDataSource1"
autogeneraterows="False"
width="312px"
height="152px">
<fields>
<asp:boundfield
visible="False"
sortexpression="EmployeeID"
datafield="EmployeeID">
</asp:boundfield>
<asp:boundfield
sortexpression="LastName"
datafield="LastName"
headertext="LastName">
</asp:boundfield>
<asp:boundfield
sortexpression="FirstName"
datafield="FirstName"
headertext="FirstName">
</asp:boundfield>
<asp:boundfield
sortexpression="Title"
datafield="Title"
headertext="Title">
</asp:boundfield>
<asp:buttonfield text="Button">
<controlstyle font-bold="True" forecolor="Red" />
</asp:buttonfield>
</fields>
</asp:detailsview>
<asp:sqldatasource
id="SqlDataSource1"
runat="server"
selectcommand="SELECT * FROM Employees"
connectionstring="<%$ ConnectionStrings:MyNorthwind%>">
</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>ASP.NET Example</title>
</head>
<body>
<form id="form1" runat="server">
<asp:detailsview
id="DetailsView1"
runat="server"
allowpaging="True"
datasourceid="SqlDataSource1"
autogeneraterows="False"
width="312px"
height="152px">
<fields>
<asp:boundfield
visible="False"
sortexpression="EmployeeID"
datafield="EmployeeID">
</asp:boundfield>
<asp:boundfield
sortexpression="LastName"
datafield="LastName"
headertext="LastName">
</asp:boundfield>
<asp:boundfield
sortexpression="FirstName"
datafield="FirstName"
headertext="FirstName">
</asp:boundfield>
<asp:boundfield
sortexpression="Title"
datafield="Title"
headertext="Title">
</asp:boundfield>
<asp:buttonfield text="Button">
<controlstyle font-bold="True" forecolor="Red" />
</asp:buttonfield>
</fields>
</asp:detailsview>
<asp:sqldatasource
id="SqlDataSource1"
runat="server"
selectcommand="SELECT * FROM Employees"
connectionstring="<%$ ConnectionStrings:MyNorthwind%>">
</asp:sqldatasource>
</form>
</body>
</html>
注解
ControlStyle属性控制派生自的类型所包含的任何 Web 服务器控件的外观 DataControlField 。The ControlStyle property governs the appearance of any Web server controls contained by types derived from DataControlField.
此属性不会影响所有派生的类型。This property does not affect all derived types. BoundField通常显示文本数据并仅包含控件的控件 TextBox 仅 ControlStyle 在处于状态时受属性的影响 Edit 。The BoundField control, which typically displays text data and contains only TextBox controls, is only affected by the ControlStyle property when in Edit state. Web 服务器控件(如 ButtonField 和) CheckBoxField 可能会受属性的影响 ControlStyle ,具体取决于字段所包含的控件对象实例的特定配置。Web server controls such as ButtonField and CheckBoxField might be affected by the ControlStyle property, depending on the specific configuration of the control object instances contained by the field. 例如, ButtonField 控件可以呈现为 LinkButton 、 ImageButton 或 Button 对象。For example, the ButtonField control can be rendered as a LinkButton, ImageButton, or Button object. 尽管 LinkButton 控件受 font 指定对象的特性的影响 Style ,但 Button 控件不受影响。Although a LinkButton control is affected by font attributes of the specified Style object, a Button control is not.