www.webdeveloper.com
Results 1 to 4 of 4

Thread: multiple drop-down boxes populated from DB on one ASP page

  1. #1
    Join Date
    Oct 2005
    Posts
    39

    multiple drop-down boxes populated from DB on one ASP page

    I have the following code to populate a dropdown box. I'm in need of anoter dropdown populated from the database on the same page.

    <%
    Dim DataConn
    Dim CmdPopulateStates
    Dim SQL

    Set DataConn = Server.CreateObject("ADODB.Connection")
    Set CmdPopulateStates = Server.CreateObject("ADODB.Recordset")
    %>

    Take away the comment on Sytem DSN version below if you want to use a system DSN instead and add a comment to the DSN-LESS connection version below it

    <%
    DataConn.Open "DBQ=" & Server.Mappath("_database/zipcodes.mdb") & ";Driver={Microsoft Access Driver (*.mdb)};"
    SQL = "SELECT DISTINCT STATE_NAME FROM STATES"
    CmdPopulateStates.Open SQL, DataConn
    %>
    <form method="POST" action="somepage.asp">
    <Select Name="STATE_NAME" size="1">
    <%While Not CmdPopulateStates.EOF%>
    <option value="<%= CmdPopulateStates("STATE_NAME") %>"><%= CmdPopulateStates("STATE_NAME") %></option>
    <%
    CmdPopulateStates.MoveNext
    Wend
    CmdPopulateStates.Close
    Set CmdPopulateStates = Nothing
    DataConn.Close
    Set DataConn = Nothing
    %>
    </Select>
    <input type="submit" value="Submit">
    </form>

    Is it as simple as creating a second recordset, sql, and repeating the "CmdPopulateStates.Open SQL, DataConn" command calling the relevant sql name?

  2. #2
    Join Date
    Dec 2005
    Location
    Blackpool, UK
    Posts
    172
    Yes, but this time change CmdPopulateStates to CmdPopulateSomethingElse.
    "To steal ideas from one person is plagiarism; to steal from many is research."

  3. #3
    Join Date
    Mar 2004
    Location
    Manila
    Posts
    17

    Re:

    select another from the table if it is in thesame table, or select it using a alias for you to get the result and then create a another combo box and populate the another field you select from the connection

    ex:

    SELECT a.STATE_NAME, b.COUNTRY_NAME from STATE as a, COUNTRY as b


    <form method="POST" action="somepage.asp">
    <Select Name="STATE_NAME" size="1">
    <%While Not CmdPopulateStates.EOF%>
    <option value="<%= CmdPopulateStates("STATE_NAME") %>"><%= CmdPopulateStates("STATE_NAME") %></option>

    <%
    CmdPopulateStates.MoveNext
    Wend

    %>
    </Select>

    <Select Name="COUNTRY_NAME" size="1">
    <%While Not CmdPopulateStates.EOF%>
    <option value="<%= CmdPopulateStates("COUNTRY_NAME") %>"><%= CmdPopulateStates("COUNTRY_NAME") %></option>

    <%
    CmdPopulateStates.MoveNext
    Wend
    CmdPopulateStates.Close
    Set CmdPopulateStates = Nothing
    DataConn.Close
    Set DataConn = Nothing
    %>
    </Select>

    <input type="submit" value="Submit">
    </form>

  4. #4
    Join Date
    Jan 2003
    Location
    USA
    Posts
    688
    And for some related links:

    Classic ASP Design Tips - Fill a Listbox Possibly With Multiple Columns
    http://www.bullschmidt.com/devtip-filllistbox.asp

    Classic ASP Design Tips - Dependent Listboxes
    http://www.bullschmidt.com/devtip-de...tlistboxes.asp
    J. Paul Schmidt
    www.Bullschmidt.com - Freelance Web and Database Developer
    www.Bullschmidt.com/DevTip.asp - Classic ASP Design Tips

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles