In This Topic
Binding a database table to a combobox can be accomplished using the following steps:
- Add the ComboBox control to your page.
- Retrieve the data from the appropriate database table. In this example, we use the C1Nwind.mdb file so copy the C1Nwind.mdb from the App_Data folder in the Control Explorer sample to your project's App_Data folder.
- Set C1ComboBox1's data properties to the following in your source page:
- DataSourceID property to AccessDataSource1. This will set the ID of the data source.
- DataTextField property to UnitPrice. This will set the field in the data source from which to load the text values.
- DataTextFormatString propertyto {0:C}. This will apply the currency formatting.
- DataValueField property to OrderID. This will load the OrderID field items into the combobox.
- Add the following to your source page:
To write code in Source View
<asp:AccessDataSource ID="AccessDataSource1" runat="server" DataFile="~/App_Data/C1NWind.mdb"
SelectCommand="SELECT top 100 [UnitPrice], [OrderID] FROM [Order Details]"></asp:AccessDataSource>
- Set C1ComboBox's Width to 160. This will allow more witdth space to accommodate the items in the dropdown box.
- Save and run your project and observe the binding values will fill the dropdown list of C1Combobox.