次の方法で共有


AttributeCollection.CssStyle プロパティ

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

名前空間: System.Web.UI
アセンブリ: System.Web (system.web.dll 内)

構文

'宣言
Public ReadOnly Property CssStyle As CssStyleCollection
'使用
Dim instance As AttributeCollection
Dim value As CssStyleCollection

value = instance.CssStyle
public CssStyleCollection CssStyle { get; }
public:
property CssStyleCollection^ CssStyle {
    CssStyleCollection^ get ();
}
/** @property */
public CssStyleCollection get_CssStyle ()
public function get CssStyle () : CssStyleCollection
適用できません。

プロパティ値

現在のサーバー コントロールのスタイルを格納している CssStyleCollection オブジェクト。

解説

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

使用例

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

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
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 void Button2_Click(Object sender, System.EventArgs e)
{
    String myColor;
    System.Web.UI.AttributeCollection myAttributes = TextBox1.get_Attributes();
    myColor = DropDownList1.get_Items().get_Item(DropDownList1.
  get_SelectedIndex()).get_Text();
    // Add the attribute "background-color" in to the CssStyle.
    myAttributes.get_CssStyle().Add("background-color",myColor);
} //Button2_Click

プラットフォーム

Windows 98,Windows Server 2000 SP4,Windows CE,Windows Millennium Edition,Windows Mobile for Pocket PC,Windows Mobile for Smartphone,Windows Server 2003,Windows XP Media Center Edition,Windows XP Professional x64 Edition,Windows XP SP2,Windows XP Starter Edition

Microsoft .NET Framework 3.0 は Windows Vista,Microsoft Windows XP SP2,および Windows Server 2003 SP1 でサポートされています。

バージョン情報

.NET Framework

サポート対象 : 3.0,2.0,1.1,1.0

参照

関連項目

AttributeCollection クラス
AttributeCollection メンバ
System.Web.UI 名前空間
CssStyleCollection