How to: Populate List Web Server Controls from a Data Source
The information in this topic applies to the following Web server controls:
You can use a list Web server control to display items that are read from a data source. Each item in the control corresponds to an item — such as a row in a data table — in the data source. The control can display one field from the source and can optionally use a second field as the item value.
You can combine list items that you create at design time with list items that are populated from a data source by setting the AppendDataBoundItems property of a list control to true. A typical example is to create a list item with the text "Select an item" as the first item for a DropDownList control. You can then populate the remaining items in the DropDownList control from the data source.
To populate a list Web server control from a data source
Add a data source control to the page, such as the SqlDataSource control or the ObjectDataSource control.
Use the Data Source Configuration Wizard to define the connection and the query, or data-retrieval method, for the data source control.
Right-click the list control and click Show Smart Tag.
In the task menu, click Choose Data Source.
The Data Source Configuration Wizard is displayed.
In the Select a data source list, click the data source control that you added in Step 1.
In the Select a data field to display list, click the data field that you want to display in the control.
Optionally, in the Select a data field for the value list, click the data field to store as the value of each item.
Optionally, if the control already contains statically defined list items that you want to retain when the list is populated from a data source, set the control's AppendDataBoundItems property to true.
See Also
Tasks
Walkthrough: Creating Master/Detail Web Pages in Visual Studio
Reference
CheckBox and CheckBoxList Web Server Controls Overview
DropDownList Web Server Control Overview
ListBox Web Server Control Overview
RadioButton and RadioButtonList Web Server Controls Overview