ASP. NET-sortedlist object

Source: Internet
Author: User

Sortedlist objects have the features of arraylist and hashtable objects.
The sortedlist object can automatically generate text and values for the following controls:

  • ASP: radiobuttonlist
  • ASP: checkboxlist
  • ASP: dropdownlist
  • ASP: ListBox

    The sortedlist object contains items represented by key/value pairs. Sortedlist objects can be automatically sorted by character or number.

    Use the add () method to add a project to sortedlist. Sortedlist can be adjusted to the final size by using the trimtosize () method.

    The followingCodeA sortedlist named mycountries is created and four elements are added:

  • To bind data to the radiobuttonlist control, first create a radiobuttonlist control in the aspx file (without any ASP: listitem element ):

    <HTML>
    <Body>

    <Form runat = "server">
    <Asp: radiobuttonlist id = "rb" runat = "server" autopostback = "true"/>
    </Form>

    </Body>
    </Html>

     Then add the build list script:

    <SCRIPT runat = "server">
    Sub page_load
    If not page. ispostback then
    Dim mycountries = new sortedlist
    Mycountries. Add ("C", "China ")
    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>

    Then we add a subroutine that will be executed when the user clicks the project in the radiobuttonlist control. When the single-choice button is clicked, the text will appear in the label:

    <SCRIPT runat = "server">
    Sub page_load
    If not page. ispostback then
    Dim mycountries = new sortedlist
    Mycountries. Add ("C", "China ")
    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> 

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