Browse DevX
Sign up for e-mail newsletters from DevX

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



Building the Right Environment to Support AI, Machine Learning and Deep Learning

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