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对象。

时间: 2024-08-01 11:32:11

net入门教程:ASP.NET Hashtable 对象 教程的相关文章

asp.net入门教程:ASP.NET SortedList 对象教程

asp.net入门教程:ASP.NET SortedList 对象教程 SortedList对象的特点相结合的ArrayList的对象和哈希表对象.   范例 例如1 -S ortedListR adioButtonList 例如2 -S ortedListR adiobuttonList 例如3 -S ortedList下拉列表   在SortedList对象 在SortedList对象包含项目的键/值对.阿SortedList自动排序对象中的项目字母或数字顺序. 项目新增至SortedLis

net 教程:ASP.NET SortedList 对象

net 教程:ASP.NET SortedList 对象 SortedList对象的特点相结合的ArrayList的对象和哈希表对象. 在SortedList对象 在SortedList对象包含项目的键/值对.阿SortedList自动排序对象中的项目字母或数字顺序. 项目新增至SortedList与购买( )方法.阿SortedList尺寸可作其最后大小与TrimToSize ( )方法. 下面的代码创建了一个SortedList命名mycountries和四个要素说: <script run

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

ASP.NET ArrayList 对象 ArrayList的对象是一个收集的项目包含一个单一的数据值. 创建一个ArrayList ArrayList的对象是一个收集的项目包含一个单一的数据值. 项目被添加到该ArrayList与购买( )方法. 下面的代码创建一个新的ArrayList对象命名mycountries和4个项目是补充说: <script runat="server"> Sub Page_Load if Not Page.IsPostBack then  

asp入门教程:ASP Session 对象简介

asp入门教程:ASP Session 对象简介 Session对象是用来储存的信息,或更改设置的一个用户会议.变量存储在Session对象举办资讯单一用户,并提供给所有的网页在一个应用程序. -------------------------------------------------- ------------------------------ Session对象 当你正与一个应用程序,你打开它,做一些改变,然后将其关闭.这是很像会议.计算机知道你是谁.它知道当您启动应用程序,当您结束

asp入门教程:ASP FileSystemObject 对象

asp入门教程:ASP FileSystemObject 对象 使用FileSystemObject对象是用来存取档案系统的服务器上. 下面我们来举例说明吧. <html> <body> <% Set fs=Server.CreateObject("Scripting.FileSystemObject") If (fs.FileExists("c:winntcursors3dgarro.cur"))=true Then       Re

asp入门教程:ASP Server 对象简单

asp入门教程:ASP Server 对象简单 在ASP服务器对象用于访问属性和方法在服务器上. 好了下面我们来看一个实例: <html> <body> <% Set fs = Server.CreateObject("Scripting.FileSystemObject") Set rs = fs.GetFile(Server.MapPath("demo_lastmodified.asp")) modified = rs.DateLa

asp入门教程:ASP Response 对象教程

asp入门教程:ASP Response 对象教程 ASP Response对象是用来发送输出到用户从服务器. 下面我们来看一个简单的例子吧. <% response.write " i love asp " %> 输出的结果为 i love asp response的作用是输出数据.的. 转载请注明来自http://www.111cn.net/asp/asp.html

asp入门教程:ASP applocation 全局变量与 Global.asa 文件

asp入门教程:ASP 全局变量 Global.asa 文件 Global.asa文件是一个可选文件,可以包含申报的对象,变量和方法,可以通过在每一页的ASP应用程序. -------------------------------------------------- ------------------------------ Global.asa文件 Global.asa文件是一个可选文件,可以包含申报的对象,变量和方法,可以通过在每一页的ASP应用程序.所有有效的浏览器的脚本( Java

ASP内置对象详解精彩教程

对象|教程|内置对象|详解 使用ASP开发动态网站我们经常使用到其中的六个内置的对象,今天给大家收集了一下供大家参考! 1.ASP内置对象详解之Session对象 [2005-03-16]     2.ASP内置对象详解之Server对象 [2005-03-16]     3.ASP内置对象详解之Response对象 [2005-03-16]     4.ASP内置对象详解之Request对象 [2005-03-16]     5.ASP内置对象详解之ObjectContext对象 [2005-