AttributeCollection.CssStyle プロパティ

定義

現在の AttributeCollection オブジェクトが属する ASP.NET サーバー コントロールのスタイルのコレクションを取得します。

public:
 property System::Web::UI::CssStyleCollection ^ CssStyle { System::Web::UI::CssStyleCollection ^ get(); };
public System.Web.UI.CssStyleCollection CssStyle { get; }
member this.CssStyle : System.Web.UI.CssStyleCollection
Public ReadOnly Property CssStyle As CssStyleCollection

プロパティ値

CssStyleCollection

現在のサーバー コントロールのスタイルを格納しているコレクション。

次の例は、CSS スタイルの値をプログラムでサーバー コントロールの AttributeCollection オブジェクトに追加する方法を示しています。 ボタンをクリックすると、名前付きのサーバー コントロールのTextBox背景色が、サーバー TextBox1 コントロールの選択した項目にDropDownListDropDownList1設定されます。

private void Button2_Click(object sender, System.EventArgs e)
{
   
   string myColor;
   AttributeCollection myAttributes = TextBox1.Attributes;
   myColor = DropDownList1.Items[DropDownList1.SelectedIndex].Text;
   // Add the attribute "background-color" in to the CssStyle.
   myAttributes.CssStyle.Add("background-color",myColor);
   
}
Private Sub Button2_Click(sender As Object, e As System.EventArgs)
   Dim myColor As String
   Dim myAttributes As AttributeCollection = TextBox1.Attributes
   myColor = DropDownList1.Items(DropDownList1.SelectedIndex).Text
   ' Add the attribute "background-color" in to the CssStyle.
   myAttributes.CssStyle.Add("background-color", myColor)
End Sub

注釈

特定の HTML サーバー コントロールに対してCssStyleCollection宣言されたすべてのスタイルは、含まれている ASP.NET Web ページが解析されるときにオブジェクトに追加されます。 このプロパティを使用すると、サーバー コントロールに対して宣言されたスタイルを追加、削除、反復処理できます。

適用対象

こちらもご覧ください