Bind ArrayList to DropDownList : ArrayList « Collections « ASP.NET Tutorial






<script language="C#" runat="server">
protected void Page_Load(object o, EventArgs e) {
    if(!IsPostBack) {
        ArrayList arrayList = new ArrayList();
        arrayList.Add("C#");
        arrayList.Add("VB.NET");
        arrayList.Add("JScript.Net");

        languageDropDownList.DataSource = arrayList;
        languageDropDownList.DataBind();

        favoriteLanguage.Text = languageDropDownList.SelectedItem.Value;
    }
}

protected void DropDownListSelectionChanged(object o, EventArgs e) {
    favoriteLanguage.Text = languageDropDownList.SelectedItem.Text;
}
</script>
<form runat="server">
<asp:DropDownList 
    id="languageDropDownList"
    runat="server" 
    OnSelectedIndexChanged="DropDownListSelectionChanged" >
</asp:DropDownList><br/>
Favorite Language: <b><asp:Label runat="server" id="favoriteLanguage" style="color:blue" /></b><br />
<asp:Button runat="server" Text="Submit"/>
</form>








7.2.ArrayList
7.2.1.Add objects to ArrayList (C#)
7.2.2.Add objects to ArrayList (VB)
7.2.3.Foreach loop (C#)
7.2.4.Foreach loop (VB)
7.2.5.Using an ArrayList instead of an array (C#)
7.2.6.Using an ArrayList instead of an array (VB)
7.2.7.Using a custom strongly typed PersonList (C#)
7.2.8.Using a custom strongly typed PersonList (VB)
7.2.9.ArrayList with custom objects
7.2.10.Bind ArrayList to DropDownList