Using the AccessDataSource Control in VS 2005 - Binding data to a drop-down list control
(Page 4 of 4 )
Configuring the data source used by the drop-down
For this purpose we shall use the same database, but create a second AccessDataSource control, AccessDataControl2, whose configuration details are as shown in this composite picture. We will only use the LastName in the drop-down list alphabetically arranged in the ascending order as shown.

This configures the AccessDataSource with the following SELECT statement:
SELECT DISTINCT LastName FROM Employees ORDER BY LastName
Binding data to drop-down list
Clicking on the "task arrow" at the top-left of the drop-down list control brings up the tasks list for this control. Clicking on the Choose Data Source... hyperlink opens up the Choose a Data Source section of the Data Source Configuration Wizard as shown. You can click on the Select a data source drop-down to reveal the available data sources configured. Since AccessDataSource2 will be used, choose this source. The Select a data field to display in the DropDownList should only show one item, namely the "LastName." This is the same, by default, for the drop-down's value for the field as shown. Since the data source has been assigned at design time there is no need to write any code.

The properties of the DropDownList1 control are as shown in this picture. All these assignments are made in the previous dialogue.

The result of displaying the control by browsing the default.aspx page is as shown in the next picture (the Show Employee Information button was not clicked).

Summary
The AccessDataSource control saves a lot of trouble and reduces the labor involved in configuring ODBC or OLEDB connections. However, its use is limited to databases which are not protected. The documentation, however, says that the base class may be used in such cases. Data binding was shown through both code, and at design time. The data source configuration wizard also includes a query designer, although one was not used in the tutorial.
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |