ASP.NET - The Hashtable Object
2007-01-19 17:13
393 查看
The Hashtable//散列表 object//对像 contains items in key/value pairs//对.
ASPX Source:
Output Result:
if you click the radio "Norway",it will shows:
Example 2 - Hashtable RadiobuttonList
ASPX Source:
Output Result:
if you click the radio "DropDownList",It will show:
Example 3
- Hashtable DropDownList//下拉菜单式列表
ASPX Source:
Output Result:
it you click the dropDownList "Italy"
Items are added to the Hashtable with the Add() method.
The following code creates a Hashtable//散列表 named mycountries and four elements//四个元素 are added:
asp:RadioButtonList //单选按钮
asp:CheckBoxList //多选框
asp:DropDownList //下拉式列表
asp:Listbox //列表框
To bind //绑定data to a RadioButtonList control, first create a RadioButtonList control (without any asp:ListItem elements) in an .aspx page:
Then add the script that builds the list://创建列表
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:
Note: You cannot choose the sort order//排序 of the items added to the Hashtable. To sort items alphabetically//按字母表顺序地 or numerically//数值, use the SortedList//分类列表 object.
Examples
Example 1 - Hashtable RadioButtonList//单选按钮列表ASPX Source:
<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> </html> |
Output Result:
|
|
ASPX Source:
<script runat="server"> sub Page_Load if Not Page.IsPostBack then dim navigate=New Hashtable navigate.Add("RadioButtonList","control_radiobuttonlist.asp") navigate.Add("CheckBoxList","control_checkboxlist.asp") navigate.Add("DropDownList","control_dropdownlist.asp") navigate.Add("ListBox","control_listbox.asp") rb.DataSource=navigate rb.DataValueField="Value" rb.DataTextField="Key" rb.DataBind() end if end sub sub navigate(s as Object, e As EventArgs) response.redirect(rb.SelectedItem.Value) end sub </script> <html> <body> <form runat="server"> <asp:RadioButtonList id="rb" runat="server" AutoPostBack="True" onSelectedIndexChanged="navigate" /> </form> </body> </html> |
Output Result:
|
if you click the radio "DropDownList",It will show:
it will open the file "control_dropdownlist.asp" in the frame of Output Result. |
- Hashtable DropDownList//下拉菜单式列表
ASPX Source:
<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") dd.DataSource=mycountries dd.DataValueField="Key" dd.DataTextField="Value" dd.DataBind() end if end sub sub displayMessage(s as Object,e As EventArgs) lbl1.text="Your favorite country is: " & dd.SelectedItem.Text end sub </script> <html> <body> <form runat="server"> <asp:DropDownList id="dd" runat="server" AutoPostBack="True" onSelectedIndexChanged="displayMessage" /> <p><asp:label id="lbl1" runat="server" /></p> </form> </body> </html> |
Output Result:
Norway Italy Sweden France |
it you click the dropDownList "Italy"
Norway Italy Sweden France Your favorite country is: Italy |
Create a Hashtable
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.
The following code creates a Hashtable//散列表 named mycountries and four elements//四个元素 are added:
<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> |
Data Binding
A Hashtable object //散列表对像may automatically generate the text and values//文本和值 to the following controls://控件asp:RadioButtonList //单选按钮
asp:CheckBoxList //多选框
asp:DropDownList //下拉式列表
asp:Listbox //列表框
To bind //绑定data to a RadioButtonList control, first create a RadioButtonList control (without any asp:ListItem elements) in an .aspx page:
<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> |
<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> </html> |
相关文章推荐
- ASP.NET - The ArrayList Object
- ASP.NET - The SortedList Object
- 解决asp.net error: Operation is not valid due to the current state of the object
- 【ASP.NET Step by Step】之六 Programmatically Setting the ObjectDataSource's Parameter Values
- ASP.NET4.0错误:Operation is not valid due to the current state of the object
- Understanding the Session Object in ASP.NET 2.0
- 【ASP.NET Step by Step】之四 Displaying Data With the ObjectDataSource
- The ASP.NET Object Model
- [导入]Thow to use the AspnetUpload control 2.1
- ASP .Net 如何动态设置ObjectDataSource 的 SelectParameters
- asp.net中使用fckeditor时,提示“this connector is disabled Please check the"editor/filemanager/connectors/aspx/config.aspx”解决办法
- The ASP.NET Page Lifecycle
- Rewrite the master page form action attribute in asp.net 2.0
- Using Templates With the ASP.NET Repeater Control...
- 关于错误:ASP.NET The URL-encoded form data is not valid.
- A low-level Look at the ASP.NET Architecture
- ASP.NET - Hashtable 对象
- The ASP.NET common Development methods
- You cannot access the client's file system using the FileSystemObject in your ASP code
- ASP.NET操作EXCEL时出现的错误 Retrieving the COM class factory for component with CLSID