Net Getting Started Tutorial: ASP. NET ArrayList object

Source: Internet
Author: User

ASP. NET ArrayList object

The ArrayList object is a collection item that contains a single data value.

Create an ArrayList
The ArrayList object is a collection item that contains a single data value.

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

The following code creates a new ArrayList object named mycountries and four projects are added:

<Script runat = "server">
Sub Page_Load
If Not Page. IsPostBack then
Dim mycountries = New ArrayList
Mycountries. Add ("Norway ")
Mycountries. Add ("Sweden ")
Mycountries. Add ("France ")
Mycountries. Add ("Italy ")
End if
End sub
</Script>
 


By default, An ArrayList object contains 16 entries. An ArrayList can be small to medium. Its final scale and TrimToSize () method:

<Script runat = "server">
Sub Page_Load
If Not Page. IsPostBack then
Dim mycountries = New ArrayList
Mycountries. Add ("Norway ")
Mycountries. Add ("Sweden ")
Mycountries. Add ("France ")
Mycountries. Add ("Italy ")
Mycountries. TrimToSize ()
End if
End sub
</Script>
An ArrayList can also be sorted alphabetically or numerical values (): <script runat = "server">
Sub Page_Load
If Not Page. IsPostBack then
Dim mycountries = New ArrayList
Mycountries. Add ("Norway ")
Mycountries. Add ("Sweden ")
Mycountries. Add ("France ")
Mycountries. Add ("Italy ")
Mycountries. TrimToSize ()
Mycountries. Sort ()
End if
End sub
</Script> the sorting order is the opposite. It is applicable to the sort () method after the reverse () method: <script runat = "server">
Sub Page_Load
If Not Page. IsPostBack then
Dim mycountries = New ArrayList
Mycountries. Add ("Norway ")
Mycountries. Add ("Sweden ")
Mycountries. Add ("France ")
Mycountries. Add ("Italy ")
Mycountries. TrimToSize ()
Mycountries. Sort ()
Mycountries. Reverse ()
End if
End sub
</Script> controls the text and values automatically generated by an ArrayList object: dynamic: RadioButtonList dynamic: CheckBoxList dynamic: pull-down list dynamic: the list box is bound 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"/>
</Form> </body>
</Html> then add the script, create a list, and combine the RadioButtonList control in the value list: <script runat = "server">
Sub Page_Load
If Not Page. IsPostBack then
Dim mycountries = New ArrayList
Mycountries. Add ("Norway ")
Mycountries. Add ("Sweden ")
Mycountries. Add ("France ")
Mycountries. Add ("Italy ")
Mycountries. TrimToSize ()
Mycountries. Sort ()
Rb. DataSource = mycountries
Rb. DataBind ()
End if
End sub
</Script> <Body> <form runat = "server">
<Asp: RadioButtonList id = "rb" runat = "server"/>
</Form> </body>
</Html> The RadioButtonList control of the DataSource attribute is set to ArrayList, which defines the RadioButtonList control of the data source. The data source bound to the RadioButtonList control and the RadioButtonList control. Note: data values are used to control two types of text and Value attributes. To add texts with different values, you can use a hash table object or SortedList object.

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.