O'Reilly logo

C# Primer: A Practical Approach by Stanley B. Lippman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

7.13. Adding a DropDownList Control

The DropDownList control allows the user to select one of any number of items. In our case we wish to present the user with the available appointment times. Unlike a list box, a drop-down list displays only one item—the item currently selected. To see the entire item list, the user clicks on the right-hand down arrow. We can either add each item individually to the list:

DropDownList1.Items.Add( "7:00 AM" );

or else assign a collection of items to the control's DataSource property—for example,

 private void Page_Load( object sender, System.EventArgs e ) { if ( ! IsPostBack ) { string [] times = { "7:00 AM", "8:00 AM", "9:00 AM", "10:00 AM", "11:00 AM", "12:00 Noon", "2:00 PM", "3:00 PM", "4:00PM" }; DropDownList1.DataSource ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required