教程集 www.jiaochengji.com
教程集 >  脚本编程  >  Asp.net  >  正文 net入门教程:ASP.NET Hashtable 对象 教程

net入门教程:ASP.NET Hashtable 对象 教程

发布时间:2018-10-02   编辑:jiaochengji.com
教程集为您提供net入门教程:ASP.NET Hashtable 对象 教程等资源,欢迎您收藏本站,我们将为您提供最新的net入门教程:ASP.NET Hashtable 对象 教程资源

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>

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


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

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

下面的代码创建一个哈希表命名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页:<html>
<body><form runat="server">
<asp:RadioButtonList id="rb" runat="server"
AutoPostBack="True" /></form></body>
</html>然后添加脚本,建立名单:<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><html>
<body><form runat="server">
<asp:RadioButtonList id="rb" runat="server"
AutoPostBack="True" /></form></body>
</html>然后,我们添加一个子例程被处决时,用户点击一个项目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><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>注意:您不能选择的排序顺序的项目增加了哈希表。项目分类按字母顺序或数值,使用SortedList对象。

您可能感兴趣的文章:
net入门教程:ASP.NET Hashtable 对象 教程
深入浅出asp.NET泛型编程.NET泛型编程入门教程
如何使用 .Net Remoting 实现定向广播
net和php哪个好学
php入门教程(索引)
PHP 底层原理之类和对象
ASP.NET 入门的五个步骤
关于.net下服务安装
通过Jquery遍历Json的两种数据结构的实现代码
C#生成不重复的随机数的几个代码

[关闭]
~ ~