Lists

ArrayList-A collection of items containing a single data value.
Use the Add method to add items to the ArrayList
| 1 |
<script runat="server"> |
| 2 |
Sub Page_Load |
| 3 |
if Not Page.IsPostBack then |
| 4 |
dim Munsters=New ArrayList |
| 5 |
Munsters.Add("Herman") |
| 6 |
Munsters.Add("Lily") |
| 7 |
Munsters.Add("Grandpa") |
| 8 |
Munsters.Add("Eddie") |
| 9 |
Munsters.Add("Marylyn") |
| 10 |
end if |
| 11 |
end sub |
| 12 |
</script> |
An ArrayList object contains 16 entries by default.
You can resize an ArrayList with the TrimToSize() method:
| 1 |
<script runat="server"> |
| 2 |
Sub Page_Load |
| 3 |
if Not Page.IsPostBack then |
| 4 |
dim Munsters=New ArrayList |
| 5 |
Munsters.Add("Herman") |
| 6 |
Munsters.Add("Lily") |
| 7 |
Munsters.Add("Grandpa") |
| 8 |
Munsters.Add("Eddie") |
| 9 |
Munsters.Add("Marylyn") |
| 10 |
Munsters.TrimToSize() |
| 11 |
end if |
| 12 |
end sub |
| 13 |
</script> |
You can sort an ArrayList alphabetically or numerically with Sort()
| 1 |
<script runat="server"> |
| 2 |
Sub Page_Load |
| 3 |
if Not Page.IsPostBack then |
| 4 |
dim Munsters=New ArrayList |
| 5 |
Munsters.Add("Herman") |
| 6 |
Munsters.Add("Lily") |
| 7 |
Munsters.Add("Grandpa") |
| 8 |
Munsters.Add("Eddie") |
| 9 |
Munsters.Add("Marylyn") |
| 10 |
Munsters.TrimToSize() |
| 11 |
Munsters.Sort() |
| 12 |
end if |
| 13 |
end sub |
| 14 |
</script> |
You can sort in reverse order using Reverse() after the Sort() method
| 1 |
<script runat="server"> |
| 2 |
Sub Page_Load |
| 3 |
if Not Page.IsPostBack then |
| 4 |
dim Munsters=New ArrayList |
| 5 |
Munsters.Add("Herman") |
| 6 |
Munsters.Add("Lily") |
| 7 |
Munsters.Add("Grandpa") |
| 8 |
Munsters.Add("Eddie") |
| 9 |
Munsters.Add("Marylyn") |
| 10 |
Munsters.TrimToSize() |
| 11 |
Munsters.Sort() |
| 12 |
Munsters.Reverse() |
| 13 |
end if |
| 14 |
end sub |
| 15 |
</script> |
List Controls

3 types
- Simple List Controls
- CheckboxList
- DropDownList
- Listbox
- RadioButtonList
- RepeaterControl
- Repeater
- ComplexListControls
- DataList
- DataGrid
Common Properties of List Controls
Property |
Description |
AutoPostBack |
Postback occurs then user changes list selection |
DataMember |
Table |
DataSource |
dataSource |
DataTextField |
Field in the dataSource to use |
DataTextFormatString |
Formatting string that controls the format of the data |
DataValueField |
What field in the data source provides the value of each list item |
Items |
Collection of items in the list control |
SelectedIndex |
Lowest index of the selected items |
SelectedItem |
Item selected with the lowest index in the list control |
Events:
OnSelectedIndexChanged
Called whenever the selection of the list control changes and is posted back to the server.