DropDownList ddl = new DropDownList(); ddl.Items.Add("Option 1"); ddl.Items.Add("Option 2"); ddl.Items.Add("Option 3");
DropDownList ddl = new DropDownList(); ddl.Items.Add("Option 1"); ddl.Items.Add("Option 2"); ddl.Items.Add("Option 3"); ddl.SelectedIndex = 1; // set the second option as selected
SqlCommand cmd = new SqlCommand("SELECT name FROM customers", conn); SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { string name = reader.GetString(0); ddl.Items.Add(name); }This example retrieves data from a SQL Server database and binds it to a DropDownList control. The package library for this class is the System.Web assembly, which is part of the .NET Framework.