AttributeCollection.Keys 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得伺服器控制項的 AttributeCollection 物件中的所有屬性的索引鍵集合。
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
屬性值
索引鍵的集合。
範例
下列範例示範如何逐一查看 Keys 伺服器控制項之 AttributeCollection 物件的 HtmlSelect 屬性。
<!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>
備註
這個屬性包含 ASP.NET 伺服器控制項中的所有 AttributeCollection 索引鍵,不論您是以程式設計方式使用 Add 方法或宣告方式新增它們。