다음을 통해 공유


CssStyleCollection.Keys 속성

정의

특정 HTML 서버 컨트롤의 CssStyleCollection 개체에 있는 모든 스타일에 대한 키 컬렉션을 가져옵니다.

public:
 property System::Collections::ICollection ^ Keys { System::Collections::ICollection ^ get(); };
public System.Collections.ICollection Keys { get; }
member this.Keys : System.Collections.ICollection
Public ReadOnly Property Keys As ICollection

속성 값

지정한 HTML 서버 컨트롤의 CssStyleCollection에 들어 있는 키 컬렉션입니다.

예제

다음 코드 예제에서는 서버 컨트롤에 대 한 컬렉션을 반복 CssStyleCollection 하는 HtmlInputText 방법을 보여 줍니다. 속성은 Keys 서버 컨트롤에서 선언된 스타일 특성을 확인하고 특성 이름과 값을 Web Forms 페이지의 개체에 바인딩하는 DataList 데 사용됩니다.

<%@ 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>
<%@ 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>

적용 대상

추가 정보