using System; using System.Web.UI; using System.Web.UI.WebControls; using System.Collections; public class TestList2 : Page { protected DropDownList StateListDrop; protected ListBox StateListBox; protected CheckBoxList StateCheckBoxList; protected RadioButtonList StateRadioButtonList; protected Label OutputDrop; protected Label OutputBox; protected Label OutputCheck; protected Label OutputRadio; void Page_Load (Object sender, EventArgs e) { if (!IsPostBack) { /***** first data source: use string array - comment this and end lines to enable string[] states = { "AL","AK","AR","AZ","CA","CO","CT","DC","DE","FL","GA","HI","IA","ID","IL","IN","KS", "KY","LA","MA","MD","ME","MI","MN","MO","MS","MT","NC","ND","NE","NH","NJ","NM","NV","NY","OH","OK", "OR","PA","RI","SC","SD","TN","TX","UT","VA","VT","WA","WI","WV","WY"}; StateListDrop.DataSource = states; StateListBox.DataSource = states; StateCheckBoxList.DataSource = states; StateRadioButtonList.DataSource = states; ****** end first method */ // /***** second data source: enumeration type - comment this and end lines to enable StateListDrop.DataSource = new States (); StateListBox.DataSource = new States (); StateCheckBoxList.DataSource = new States (); StateRadioButtonList.DataSource = new States (); // ****** end second method */ StateListDrop.DataBind (); StateListBox.DataBind (); StateCheckBoxList.DataBind (); StateRadioButtonList.DataBind (); // demonstrate enumeration type OutputDrop.Text = "demo States enumeration: "; foreach(string state in new States()) OutputDrop.Text += " " + state; } } public void OnRadioSelect (Object sender, EventArgs e) { OutputRadio.Text = "Changed Radio Selection to: " + StateRadioButtonList.SelectedItem.Text; } public void OnSubmit (Object sender, EventArgs e) { ArrayList multipleStates = GetSelectedItems (StateCheckBoxList); OutputDrop.Text = "Drop Selection is: " + StateListDrop.SelectedItem.Text; OutputBox.Text = "ListBox Selection is:" + StateListBox.SelectedItem.Text; OutputRadio.Text = "Radio Button Selection is:" + StateRadioButtonList.SelectedItem.Text; OutputCheck.Text = "Check List Selection is: "; foreach (string state in multipleStates) { OutputCheck.Text += " " + state; } } ArrayList GetSelectedItems (CheckBoxList lb) { ArrayList a = new ArrayList (); for (int i=0; i