Populating a Selectbox
This script populates a selectbox with values from a database table and selects the correct item for the current record.
<SELECT NAME="cboSomefield">
<%
Dim objConn, objRS, objRS2
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.Open "DSN=SomeDSN;"
Set objRS = objConn.Execute("SELECT CategoryID FROM SomeTable WHERE
SomeField = " & Request.QueryString("id"))
If Not objRS.EOF Then
objRS2 = objConn.Execute("SELECT CategoryID FROM SomeOtherTable")
While Not objRS2.EOF
%>
<OPTION VALUE="<%=objRS2("CategoryID")%>"<%If objRS2("CategoryID") =
objRS("CategoryID") Then Response.Write "
SELECTED"%>><%=objRS2("CategoryID")%>
<%
objRS.MoveNext
Wend
objRS2.Close
Set objRS = Nothing
End If
%>
</SELECT>
Submitted by Peter McMahon