faqts : Computers : Programming : Languages : Asp : ASP/VBScript : Common Problems : forms and user input

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

26 of 33 people (79%) answered Yes
Recently 8 of 10 people (80%) answered Yes

Entry

How do I populate a combo box in a search form with values from a two columns of a query?

Jun 23rd, 2000 17:45
Chris Durkin, James Mugauri, unknown unknown,


I assume that by "query" you mean an ADO Recordset. 
If so, here's an example:
---------------------------------------------------------------
<html>
<head>
<%
dim rst
dim vData
dim qt, crlf
qt = chr(34)
crlf = chr(13)
set conn = server.createobject("ADODB.Connection")
set rst = server.createobject("ADODB.Recordset")
conn.open "DSN=your dsn", "username", "password"
set rst = conn.execute("select col_1, col_2 from tablename")
vData = rst.GetRows
%>
</head>
<body>
<form>
<select>
<%for x = 0 to UBound(vData, 2)%>
  <%="<option value=" & qt & vData(0, x) & qt & ">"%>
  <%=vData(1, x) & "</option>" & crlf%>
<%next%>
</select>
</form>
</body>
</html>



© 1999-2004 Synop Pty Ltd