【www.gdgbn.com--基础入门】

ASP.NET Hashtable 对象 教程

在哈希表对象包含项目的键/值对。

看个例子.

<script  runat="server">
sub Page_Load
if Not Page.IsPostBack then
   dim mycountries=New Hashtable
   mycountries.Add("N","Norway")
   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>



AutoPostBack="True" onSelectedIndexChanged="displayMessage" />



创建一个哈希表
在哈希表对象包含项目的键/值对。把钥匙是用来作为指标,并很快搜索可以用于搜索的价值通过他们的钥匙。

项目被添加到哈希表与购买( )方法。

下面的代码创建一个哈希表命名mycountries和四个要素说:

<script runat="server">
Sub Page_Load
if Not Page.IsPostBack then
  dim mycountries=New Hashtable
  mycountries.Add("N","Norway")
  mycountries.Add("S","Sweden")
  mycountries.Add("F","France")
  mycountries.Add("I","Italy")
end if
end sub
</script>
数据绑定阿哈希表对象可自动生成的文字和价值观下列管制: 动态: RadioButtonList 动态: CheckBoxList 动态:下拉列表动态:列表框绑定数据到RadioButtonList控件,首先创建一个RadioButtonList控件(无任何ASP : ListItem元素)的。 aspx页:


AutoPostBack="True" />

然后添加脚本,建立名单:<script runat="server">
sub Page_Load
if Not Page.IsPostBack then
  dim mycountries=New Hashtable
  mycountries.Add("N","Norway")
  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
</script>

AutoPostBack="True" />

然后,我们添加一个子例程被处决时,用户点击一个项目RadioButtonList控件。当一个单选按钮被点击,一个文本将出现在一个标签:<script runat="server">
sub Page_Load
if Not Page.IsPostBack then
  dim mycountries=New Hashtable
  mycountries.Add("N","Norway")
  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 subsub displayMessage(s as Object,e As EventArgs)
lbl1.text="Your favorite country is: " & rb.SelectedItem.Text
end sub
</script>

AutoPostBack="True" onSelectedIndexChanged="displayMessage" />



注意:您不能选择的排序顺序的项目增加了哈希表。项目分类按字母顺序或数值,使用SortedList对象。

本文来源:http://www.gdgbn.com/asp/17231/