Results 1 to 2 of 2

Thread: Dynamically add values to a drop down box (<Selection ...)

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2000
    Location
    Canada
    Posts
    70
    I have a form with 5 "Selection"/ drop down options.
    When loading the file I would like to populate
    these options with values from a table.
    For example, one would show country names with country
    codes as their value. Another would show languages with
    language codes as their value. Next would be Reseller Codes.
    Fourth, employee names with their IDs as the value, etc.

    I've found doing this dynamically makes for an incredibly
    slow page.

    Any Suggestions?




  2. #2
    Frenzied Member monte96's Avatar
    Join Date
    Sep 2000
    Location
    Somewhere in AZ
    Posts
    1,379
    Try this:

    Code:
    <%
    Dim rs
    Dim cn
    Dim arrCompanies
    Dim strSQL
    Dim intLoop
    
    Set cn = Server.CreateObject("ADODB.Connection")
    cn.ConnectionString = "{Insert your connection info here}"
    cn.Open
    
    strSQL = "Select CompanyID, CompanyName From Companies"
    Set rs = Server.CreateObject("ADODB.Recordset")
    rs.Open strSQL, cn, adOpenForwardOnly
    If Not rs.EOF Then
        arrCompanies = rs.GetRows
    Else
        ReDim arrCompanies(0,0)
        arrCompanies(0,0) = 0
        arrCompanies(1,0) = "None Found"
    End If
    rs.Close
    Set rs = Nothing
    cn.Close
    Set cn = Nothing
    
    %>
    <HTML>
    <BODY>
    <FORM name=myForm id=MyForm action=MyPage.asp method=post>
    <SELECT>
    <%
        For intLoop = 0 to UBound(arrCompanies, 2)
            Response.Write "<OPTION value=" & Chr(34) & arrCompanies(0, intLoop) & Chr(34) & ">" & arrCompanies(1, intLoop) & "</OPTION>"
        Next
    %>
    </SELECT>
    </FORM>
    </BODY>
    </HTML>
    Array access is faster than recordset access. Also, consider if possible to use stored procedures that return your recordsets. Again, this is faster than an inline SQL query. (If your using access, this isn't really an option)
    oOOo--oOOo
    __/\/\onte96
    oOOo--oOOo
    Senior Programmer/Analyst
    MCP
    [email protected]
    [email protected]


    Your results may vary.. some restrictions may apply.. pricing and participation may vary.. not available in all states.. professional driver closed course..quantities limited..

Posting Permissions

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



Click Here to Expand Forum to Full Width