Dictionary
The Dictionary is a really cool code base item that can is a name “look up” object conventional lists… It is declared by the new 2.0 Framework namespace of Collections.Generic
check out the codebehind below ::
using System.Collections.Generic;
public partial class _Default : System.Web.UI.Page
{
private Dictionary
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
regionCountryData = new Dictionary
// here I create my first item to list and populate the entries
regionCountryData[”Americas”] = new ListItem[] {
new ListItem(”USA”),
new ListItem(”Canada”),
new ListItem(”Brazil”)
};
// here I create my second item cllection
regionCountryData[”EMEA”] = new ListItem[] {
new ListItem(”Switzerland”),
new ListItem(”Dubai”),
new ListItem(”Nigeria”)
};
// and third
regionCountryData[”Asia Pacific”] = new ListItem[] {
new ListItem(”India”),
new ListItem(”Japan”),
new ListItem(”Australia”)
};
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
RegionList.Items.Add(”—Please select—”);
foreach (string region in regionCountryData.Keys)
{
RegionList.Items.Add(region);
}
CountryList.Items.Add(”—Please select—”);
}
}
}
- - - - - S P O N S O R I N G A D V E R T I S M E N T - - - - -