|
By default, an ArrayList object contains 16 entries and an ArrayList can be sized to its final size with the 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 numerically or alphabetically with the Sort() 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()
end if
end sub
</script>
|
|
|
Apply the Reverse() method after the Sort() method to sort in reverse order,
|
<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>
|
|
|
Data Binding to an ArrayList
|
|
An ArrayList object may automatically generate the values and text to the following controls:
- asp:RadioButtonList
- asp:DropDownList
- asp:CheckBoxList
- asp:Listbox
First create a RadioButtonList control (without any asp:ListItem elements) in
an .aspx page to bind data to a RadioButtonList control:
|
<html>
<body>
<form runat="server">
<asp:RadioButtonList id="rb" runat="server" />
</form>
</body>
</html>
|
|
|
Then add the script that binds the values and builds the list in the list to the RadioButtonList control:
|
<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>
<html>
<body>
<form runat="server">
<asp:RadioButtonList id="rb" runat="server" />
</form>
</body>
</html>
|
|
|
The DataSource property of the RadioButtonList control is used to set to the ArrayList and it defines the data source of the RadioButtonList control and the DataBind() method of the RadioButtonList control binds the data source with the RadioButtonList control.
Note: The data values are used as both the Text and Value properties for the control and to add Values that are different from the Text, use either the Hashtable object or the SortedList object.
|
Share And Enjoy:These icons link to social bookmarking sites where readers can share and discover new web pages.
Keywords:
ASP.NET using The ArrayList Object,
vb net arraylist,
asp net arraylist,
visual basic arraylist,
vb net using,
asp net object,
vb net object,
visual basic object,
visual basic using,
asp net using,
java arraylist,
c# arraylist,
arraylist sort,
arraylist example,
c# using,
arraylist api,
arraylist methods,
arraylist int,
arraylist string,
java object,
jsp arraylist,
arraylist collection,
arraylist method,
vb arraylist,
arraylist vector,
arraylist constructor,
arraylist serializable,
arraylist tostring,
arraylist add,
arraylist get,
c# object,
arraylist type,
arraylist struts,
static arraylist