ComponentOne ComboBox for ASP.NET: ComboBox for ASP.NET AJAX Task-Based Help > Binding C1ComboBox to a Data Source

Binding C1ComboBox to a Data Source

This topic demonstrates how to bind C1ComboBox to a data source control. Once bound, you can use the DataTextField property to populate the C1ComboBox drop-down list. In this example, we'll use the C1ListDemo.mdb file installed by default in the C:\Documents and Settings\<username>\My Documents\ComponentOne Samples\Common (Windows XP) or C:\Users\<username>\Documents\ComponentOne Samples\Common (Windows 7/Vista) folder.

To bind C1ComboBox to a data source control, complete the following steps:

1.   In the Solution Explorer, right-click the App_Data folder, and then click Add Existing Item.

2.   Locate the C1ListDemo.mdb file.

3.   In the Add Existing Item dialog box, click the C1ListDemo.mdb file, and then click Add.

4.   Go back to the Default.aspx page.

5.   Select the C1ComboBox control, and click the Smart Tag to open the C1ComboBox Tasks menu.

6.   Click the Choose Data Source drop-down arrow and select <New data source>.

7.   In the Data Source Configuration Wizard, select Access Database and click OK.

8.   Click Browse and select App_Data under Project folders in the Select Microsoft Access Database dialog box.

9.   Choose C1ListDemo.mdb in the Contents of folder pane on the right-hand side and click OK.

10.  Click Next. The Configure the Select Statement window appears.

a.   Confirm that the Specify columns from a table or view option is selected.

b.   In the Name drop-down list, select Customer.

c.    In the Columns box, select UserCode, LastName, and FirstName or any other desired check boxes.

11.  Click Next. The Test Query page appears. Optionally, click Test Query to test your query.

12.  Click Finish to close the wizard and add the data source.

13.  Click the smart tag again to open the C1ComboBox Tasks menu.

14.  Click the drop-down arrow next to the DataTextField property and select LastName. Customers' last names will appear in the drop-down list of the C1ComboBox control.

15.  Click the drop-down arrow next to the DataValueField property and select UserCode.


Send comments about this topic to ComponentOne.
Copyright © 1987-2010 ComponentOne LLC. All rights reserved.