Easy Tutorial
❮ Prop Webcontrol Style Borderwidth Prop Webcontrol Standard Bordercolor ❯

ASP.NET Web Forms - ArrayList Object


The ArrayList object is a collection of items containing individual data values.


Try It - Example

ArrayList DropDownList

ArrayList RadioButtonList


Creating an ArrayList

The ArrayList object is a collection of items containing individual data values.

Items are added to the ArrayList using the Add() method.

The following code creates an ArrayList object named mycountries and adds four items:

By default, an ArrayList object contains 16 entries. You can adjust the ArrayList to its final size using the TrimToSize() method:

The ArrayList can also be sorted alphabetically or numerically using the Sort() method:

To reverse the sort order, apply the Reverse() method after the Sort() method:


Binding Data to ArrayList

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

To bind data to a RadioButtonList control, first create a RadioButtonList control in the .aspx page (without any asp:ListItem elements):

Then add the script to create the list and bind the values from the list to the RadioButtonList control:

Example

The DataSource property of the RadioButtonList control is set to the ArrayList, which defines the data source for the RadioButtonList control. The DataBind() method of the RadioButtonList control binds it to the data source.

Note: Data values are used as both the Text and Value properties of the control. To add a Value different from the Text, use a Hashtable object or a SortedList object.

❮ Prop Webcontrol Style Borderwidth Prop Webcontrol Standard Bordercolor ❯