AttributeCollection.Keys Property
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Gets a collection of keys to all attributes in the server control's AttributeCollection object.
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
Property Value
The collection of keys.
Examples
The following example shows how to iterate through the Keys property of the AttributeCollection object for an HtmlSelect server control.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script language="C#" runat="server">
void Page_Load(Object Src, EventArgs e)
{
Message.InnerHtml +=
"<h5>The FirstSelect select box's " +
"Attribute collection contains:</h5>";
IEnumerator keys =
FirstSelect.Attributes.Keys.GetEnumerator();
while (keys.MoveNext())
{
String key = (String)keys.Current;
Message.InnerHtml += key + "=" +
FirstSelect.Attributes[key] + "<br />";
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Attribute Collection Sample</title>
</head>
<body>
<p>
<span id="Message" enableviewstate="false"
runat="server" />
</p>
<p>
Make a selection:
<select id="FirstSelect" runat="server"
style="padding:1; width:40; font: 16pt verdana;
background-color:Aqua; color:black;">
<option>This</option>
<option>That</option>
<option>Other</option>
</select>
</p>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script language="VB" runat="server">
Sub Page_Load(Src As Object, e As EventArgs)
Message.InnerHtml = Message.InnerHtml & _
"<h5>The FirstSelect select box's " & _
"Attribute collection contains:</h5>"
Dim keys As IEnumerator = _
FirstSelect.Attributes.Keys.GetEnumerator
Do While keys.MoveNext
Dim key As String = keys.Current
Message.InnerHtml = Message.InnerHtml & key _
& "=" & FirstSelect.Attributes(key) & "<br />"
Loop
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Attribute Collection Sample</title>
</head>
<body>
<p>
<span id="Message" enableviewstate="false"
runat="server" />
</p>
<p>
Make a selection:
<select id="FirstSelect" runat="server"
style="padding:1; width:40; font: 16pt verdana;
background-color:Aqua; color:black;">
<option>This</option>
<option>That</option>
<option>Other</option>
</select>
</p>
</body>
</html>
Remarks
This property contains all the keys that are in the AttributeCollection of an ASP.NET server control, whether you have added them programmatically with the Add method, or declaratively.
Applies to
See also
GitHub에서 Microsoft와 공동 작업
이 콘텐츠의 원본은 GitHub에서 찾을 수 있으며, 여기서 문제와 끌어오기 요청을 만들고 검토할 수도 있습니다. 자세한 내용은 참여자 가이드를 참조하세요.
.NET