您的位置:首页 > 编程语言 > ASP

ASP.NET - Hashtable 对象

2008-09-28 11:21 176 查看

创建 Hashtable

Hashtable 对象包含用键/值对表示的项目。键被用作索引,通过搜索其键,可以实现对值的快速搜索。

通过 Add() 方法向 Hashtable 添加项目。

下面的代码创建一个名为 mycountries 的 Hashtable,并添加了四个元素:

<script runat="server">
sub Page_Load
if Not Page.IsPostBack then
dim mycountries=New Hashtable
mycountries.Add("C","China")
mycountries.Add("S","Sweden")
mycountries.Add("F","France")
mycountries.Add("I","Italy")
rb.DataSource=mycountries
rb.DataValueField="Key"
rb.DataTextField="Value"
rb.DataBind()
end if
end sub

sub displayMessage(s as Object,e As EventArgs)
lbl1.text="Your favorite country is: " & rb.SelectedItem.Text
end sub
</script>

<html>
<body>

<form runat="server">
<asp:RadioButtonList id="rb" runat="server"
AutoPostBack="True" onSelectedIndexChanged="displayMessage" />
<p><asp:label id="lbl1" runat="server" /></p>
</form>

</body>
</html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: