PDA

Click to See Complete Forum and Search --> : Dynamically add values to a drop down box (<Selection ...)


rlb_wpg
Oct 19th, 2000, 10:29 AM
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?

monte96
Oct 19th, 2000, 11:02 AM
Try this:


<%
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)