Net Getting Started Tutorial: ASP. NET Hashtable object tutorial

Source: Internet
Author: User

ASP. NET Hashtable object tutorial

The hash table object contains the key/value pairs of the project.

Let's look at an example.

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


Create a hash table
The hash table object contains the key/value pairs of the project. Use the key as an indicator and quickly search for the value that can be used for search through their key.

The project is added to the hash table and the purchase () method.

The following code creates a hash table named mycountries and describes the four elements:

<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>
Controls the text and values automatically generated by data-bound hash table objects: dynamic: RadioButtonList dynamic: CheckBoxList dynamic: drop-down list dynamic: the list box binds data to the RadioButtonList control, first, create a RadioButtonList control (without any ASP: ListItem element. Aspx page: <Body> <form runat = "server">
<Asp: RadioButtonList id = "rb" runat = "server"
AutoPostBack = "True"/> </form> </body>
</Html> add a script and create a list: <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> <Body> <form runat = "server">
<Asp: RadioButtonList id = "rb" runat = "server"
AutoPostBack = "True"/> </form> </body>
</Html> then, when we add a subroutine to be executed, the user clicks a project RadioButtonList control. When a single-choice button is clicked, a text will appear in a tag: <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> <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> Note: a hash table is added for items in the sorting order that you cannot select. Project categories use SortedList objects in alphabetical order or numeric values.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.