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.