Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.

Tip of the Day
Language: Active Server Pages (ASP)
Expertise: Beginner
May 8, 2000



Application Security Testing: An Integral Part of DevOps

Populating ListBox from Recordset Values


I am trying to populate a drop-down listbox with the data from a table within my database and a blank line. The code I am using is as follows:

<title>Fees Test</title>

'name the variables
Dim dcGamelvl
Dim rsGamelvl
Dim OptionString

'establish my connection
Set dcGamelvl = Server.CreateObject("ADODB.Connection")
Set rsGamelvl = Server.CreateObject("ADODB.Recordset")

dcGamelvl.Open "assignor"
rsGamelvl.Open "SELECT * FROM gamelvl", dcGamelvl

'fill my variables witht the table data
OptionString = ""

Do Until rsGamelvl.EOF
            OptionString = OptionString &_
                       "<OPTION VALUE='" & rsGamelvl("levelid")
                & "'>" &_

'close my connection

Set rsGamelvl = Nothing
Set dcGamelvl = Nothing

<form action="updateFees.asp" method=post>
            <h3>Game Level</h3>
            <SELECT SIZE=1 NAME="levelid">
                        <%= OptionString %>
        <h3><INPUT TYPE="SUBMIT" ACTION="updatefees.asp" VALUE="Submit Data"
        id=SUBMIT1 name=SUBMIT1><INPUT TYPE="RESET" VALUE="Reset Data"
        id=RESET1 name=RESET1></h3>

When I call up the ASP page, the page appears, but the dropdown box is empty. What am I doing wrong?


Your drop-down box is empty because you did not place any values in it.

An HTML drop-down box (a <SELECT> control) has two parts. The VALUE determines what will be sent back when the user selects something. The text between the tags <OPTION></OPTION> is what is displayed in the list box.

If you notice your code, you are placing a 'VALUE=' property, but you have nothing between your <OPTION></OPTION> tag pairs. So you have an empty list box.

Change your code to read:

            OptionString = OptionString &_
                         "<OPTION VALUE='" & rsGamelvl("levelid")& "'>" &_ 
                rsGamelvl("NNNNNNNN") & _

DevX Pro
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date