Contains the HTML cascading-style sheets (CSS) inline style attributes for a specified HTML server control. This class cannot be inherited.
Assembly: System.Web (in System.Web.dll)
<AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level := AspNetHostingPermissionLevel.Minimal)> _ Public NotInheritable Class CssStyleCollection
Dim instance As CssStyleCollection
[AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)] public sealed class CssStyleCollection
[AspNetHostingPermissionAttribute(SecurityAction::LinkDemand, Level = AspNetHostingPermissionLevel::Minimal)] public ref class CssStyleCollection sealed
public final class CssStyleCollection
Any style declared for a particular HTML server control is added to the collection when the containing Web Forms page is parsed. It automatically parses and exposes CSS properties through a dictionary pattern API. You can manipulate any CSS property on a server control through the Style property. Simply use the CSS property's key and value in the indexed collection.
The following code example iterates through the CssStyleCollection object for an HtmlInputText server control. The Keys property is used to determine which style attributes have been declared on the server control, and then binds the attribute names and values to a DataList object on the Web Forms page.
<%@ Page Language="VB" %> <%@ Import Namespace="System.Data" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script runat="server"> Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Dim dt As New DataTable() Dim dr As DataRow dt.Columns.Add(New DataColumn("AttributeName", GetType(String))) dt.Columns.Add(New DataColumn("AttributeValue", GetType(String))) ' The Style property of the MyText control returns ' a CssStyleCollection object. Dim keys As IEnumerator = MyText.Style.Keys.GetEnumerator() While keys.MoveNext() Dim key As [String] = CType(keys.Current, [String]) dr = dt.NewRow() dr(0) = key dr(1) = MyText.Style(key) dt.Rows.Add(dr) End While Dim dv As New DataView(dt) MessageList.DataSource = dv MessageList.DataBind() End Sub </script> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>CssStyleCollection Example</title> </head> <body> <form id="form1" runat="server"> <div> <asp:DataList id="MessageList" runat="server"> <HeaderStyle Font-Bold="true"/> <HeaderTemplate> HtmlInputText control's CssStyleCollection </HeaderTemplate> <ItemTemplate> Attribute: <%# DataBinder.Eval(Container.DataItem, "AttributeName") %> , Value: <%# DataBinder.Eval(Container.DataItem, "AttributeValue") %> </ItemTemplate> </asp:DataList> <br /> <input id="MyText" type="text" value="Type a value here." style="font: 14pt verdana;width:300;" runat="server"/> </div> </form> </body></html>
<%@ Page Language="C#" %> <%@ Import Namespace="System.Data" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script runat="server"> protected void Page_Load(object sender, EventArgs e) { DataTable dt = new DataTable(); DataRow dr; dt.Columns.Add(new DataColumn("AttributeName", typeof(String))); dt.Columns.Add(new DataColumn("AttributeValue", typeof(String))); // The Style property of the MyText control returns // a CssStyleCollection object. IEnumerator keys = MyText.Style.Keys.GetEnumerator(); while (keys.MoveNext()) { String key = (String)keys.Current; dr = dt.NewRow(); dr[0] = key; dr[1] = MyText.Style[key]; dt.Rows.Add(dr); } DataView dv = new DataView(dt); MessageList.DataSource = dv; MessageList.DataBind(); } </script> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>CssStyleCollection Example</title> </head> <body> <form id="form1" runat="server"> <div> <asp:DataList id="MessageList" runat="server"> <HeaderStyle Font-Bold="true"/> <HeaderTemplate> HtmlInputText control's CssStyleCollection </HeaderTemplate> <ItemTemplate> Attribute: <%# DataBinder.Eval(Container.DataItem, "AttributeName") %> , Value: <%# DataBinder.Eval(Container.DataItem, "AttributeValue") %> </ItemTemplate> </asp:DataList> <br /> An input control with a style attribute: <br /> <input id="MyText" type="text" value="Type a value here." style="font: 14pt verdana;width:300;" runat="server"/> </div> </form> </body> </html>
-
AspNetHostingPermission
for operating in a hosted environment. Demand value: LinkDemand; Permission value: Minimal.
System.Web.UI.CssStyleCollection
Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.