ASP. NET Web Forms-SortedList object, formssortedlist

Source: Internet
Author: User

ASP. NET Web Forms-SortedList object, formssortedlist

ASP. NET Web Forms-SortedList object

SortedList objects combine the features of ArrayList objects and Hashtable objects.

SortedList object

The SortedList object contains items represented by key/value pairs. SortedList objects are automatically sorted in alphabetical or numerical order.

Use the Add () method to Add a project to SortedList. Adjust SortedList to the final size using the TrimToSize () method.

The following code creates a SortedList object named mycountries and adds four elements:

Data Binding

The SortedList object can automatically generate text and values for the following controls:

AutoPostBack = "True" onSelectedIndexChanged = "displayMessage"/>

Asp: RadioButtonList

Asp: CheckBoxList

Asp: DropDownList

Asp: Listbox

To bind data to the RadioButtonList control, you must first create a RadioButtonList control (without any asp: ListItem element) on the. aspx page ):

Then add the script for creating the list and bind the values in the list to the RadioButtonList control:

Then we add a child routine. When you click a project in the RadioButtonList control, the child routine will be executed. When a single-choice button is clicked, a line of text appears in the label.

<Script runat = "server">
Sub Page_Load
If Not Page. IsPostBack then
Dim mycountries = New SortedList
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>

Related Article

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.