| UD40 | Ultradev Tutorials |
| |
Home | Search | Back |
| Tutorial 5 - Setting the initial value of a dropdown list to the value stored in a database | |
The tutorial title is a mouthful, but it is an often-required feature, especially
in admin pages where one has to show the existing value as well as offer
the other possible choices for users to select. I am going to
use a fictional classical music store as an example.As usual let's take a look at the database design. It has a simple structure with 4 fields as shown here. Now let us proceed to build the update form, and populate the form fields with all the relevant choices, and naming the fields according to the database field name that the information is associated with. After that we will need to build a recordset to select the relevant information from the database. The SQL can be different depending on which part of an application this comes in, but for our demo a simple SELECT * FROM Music would suffice. Go to each and every one of the dropdown list and add a new value by selecting the + button. Click on the little lightning symbol and select from the recordset the relevant field that is associated with the dropdown list. ![]() Move the newly created Label-Value pair to the top and make it as the Initially Selected value. ![]() At this stage you are done if you have only a single dropdown box on your page. However if you have more than one, like in this tutorial we have three, there is one more step to do. Switch to the HTML Source window and locate the code for the dropdown lists and you will see something like this: The final step is to delete ALL the yellow-colored ASP code blocks enclosed between the <%%> tags. For our example we should have 6 of them, a pair each for each dropdown box. If you don't do this step the choices in your dropdown box wouldn't be correct beyond the first box.
|
|
Copyright © 2001, Swee Hoe Ong All rights reserved. |