How to Use the ListBox Control in ASP.NET 2.0 - Steps in converting a Unbound ListBox to a Bound ListBox (Page 6 of 6 )
The starting point is to drop a ListBox control on the design pane. Then click the smart tag arrow attached to the ListBox at top right to open the tasks window as shown.

Now click the Choose Data Source... hyperlink to open the next page of the wizard.
In this wizard use the drop-down to choose AccessDataSource1. This may open up other drop-downs. Since you are not sure of the item and the dropdown does not show any items, just click OK.
This modifies the task list to add a new item, Configure Data Source... as shown.

Click on Configure Data Source settings, which opens up the next screen. This screen comes up with the datasource you have already configured as shown in the next picture.

Click on the Next button to reveal the next screen, Configure the Select Statement. Here you can do a lot of filtering and sorting of data using all the clauses of the SQL SELECT statement. For this example only the "City" column is chosen.

A click on the next button takes you to the following screen, Test Query, where you can test the query as shown using the Test Query button.

When you click the Finish button you get bound to data as shown in the next picture. You may also enable AutoPostBack.

Summary
This tutorial described the various ways a ListBox server control in ASPNET 2.0 gets populated with either hard coded data or data from a backend database. An MS Access 2003 database was used. The ADO.NET 2.0 Data Source Controls makes the coding much easier. The GUI provides all the necessary items for fashioning appropriate queries.
The ListBox event can be put to good use in drilling down on the data. Much of the drudgery encountered in ADO.NET 1.0 is removed for good. When configuring tasks it is advisable to switch to the source code and verify that the elements are properly configured. If you still want to use the tortuous route, you can take the route suggested in one of the examples.
| 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. |