当前位置: 首页 > 网络学院 > 服务端脚本教程 > ASP.NET > ASP.NET - The Hashtable Object 哈希表对象
The Hashtable object contains items in key/value pairs.
哈希表对象包含项目中的 键/值 对
Example 1 - Hashtable RadioButtonList
Example 2 - Hashtable RadiobuttonList
Example 3 - Hashtable DropDownList
The Hashtable object contains items in key/value pairs. The keys are used as indexes, and very quick searches can be made for values by searching through their keys.
哈希表对象包含项目中的 键/值 对。键作为索引来使用,而且通过搜索它们(值)的键可以很快的找到对应的值
Items are added to the Hashtable with the Add() method.
使用Add()方法可以往哈希表中加入项目。
The following code creates a Hashtable named mycountries and four elements are added:
以下代码建立一名为 mycountries 的哈希表并且要加入四个元素:
<script runat="server"> |
A Hashtable object may automatically generate the text and values to the following controls:
哈希对象可以自动的往以下这些控件里生成文字以及值:
To bind data to a RadioButtonList control, first create a RadioButtonList control (without any asp:ListItem elements) in an .aspx page:
要给RadioButtonList控件绑定数据,首先要在.aspx页面中建立一个RadioButtonList 控件(不需要任何asp:ListItem元素):
<html> <form runat="server"> </body> |
Then add the script that builds the list:
然后加入脚本,绑上列表:
<script runat="server"> <html> <form runat="server"> </body> |
Then we add a sub routine to be executed when the user clicks on an item in the RadioButtonList control. When a radio button is clicked, a text will appear in a label:
然后我们加入一个子程序,当用户点了RadioButtonList 控件中的一个项目后就会执行里面的代码。当按钮被点下,一段文字就会显示在标签里:
<script runat="server"> sub displayMessage(s as Object,e As EventArgs) <html> <form runat="server"> </body> |
Note: You cannot choose the sort order of the items added to the Hashtable. To sort items alphabetically or numerically, use the SortedList object.
注意:你不能对哈希表中的项目进行排序选择。要以字母或是数字的方式进行排序要使用 SortedList 对象。