PDA

View Full Version : Dropdown crashing page


tomo84
11-06-2004, 09:29 AM
Hi again,

I have a coldfusion model of what I want to do but I can't seem to easily
transform it into an ASP model that works. How do I make the following code
work to insert the CategoryID from the Categories table into the corresponding column in the Products table?

And how can I make the selected product category be initially selected for the Update Record form?

<%
Dim SelectedCategoryID
SelectedCategoryID = 1



Call PopulateDropDown( SelectedCategoryID )

' *********************************
' Populate Drop Down Sub Routine
' *********************************
Sub PopulateDropDown(byVal SelectedCategoryID)
Dim objConn
Dim objRS
Dim strSQL
Dim CategoryID
Dim CategoryName

Const adOpenForwardOnly = 0
Const adLockReadOnly = 1

Set objConn = Server.CreateObject("ADODB.Connection")
Set objRS = Server.CreateObject("ADODB.Recordset")

objConn.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & _
Server.MapPath("inov8test.mdb")

strSQL = "SELECT categoryID, CategoryName FROM Categories"

objRS.Open strSQL, objConn, adOpenForwardOnly, adLockReadOnly

Response.Write "<SELECT Name=""categoryID"">"
Response.Write "<OPTION Value=""""></OPTION>"

' Loop through the recordset and populate the dropdown
Do Until objRS.EOF = True
categoryID = objRS("categoryID").Value
categoryName = objRS("categoryName").Value

If CategoryID = SelectedCategoryID Then
Response.Write "<OPTION Value=""" & categoryID & """ SELECTED>"
Response.Write categoryName
Response.Write "</OPTION>"
Else
Response.Write "<OPTION Value=""" & categoryID & """>"
Response.Write categoryName
Response.Write "</OPTION>"
End If

objRS.Movenext
Loop

Response.Write "</SELECT>"

objRS.Close
Set objRS = Nothing
Set objConn = Nothing
End Sub
%>

Best regards,
tomo84

Roy Sinclair
11-08-2004, 04:35 PM
What "Products table"? Sorry but you've not provided enough information to get an answer yet.