ASP Drop down menu

J.B

J.B

Soldato
Joined
16 Aug 2006
Posts
5,924
Hey guys, I was hoping someone could help me, Im not great at this ASP or SQL thing but i know the basics.

What I would like is a drop down menu <select> where the <option>'s are generated from a field in the database. I've got the connection to the db, just cant work out the actual select and options part of the form.

Thanks
 
I assume if you have the db connection sorted you have the SELECT statement done and a recordset of the data you wish to add to the combo.

if so:
Code:
combobox1.items.add(recordset[0]);
etc...

Haven't used db connections in .net yet so don't really no the whole recordset bit but that structure will enable you to add items to the list.
 
not having much luck with that, where abouts would i put it in the code, sorry for being an idiot!
 
Sure thing, I've kinda got it working a different way:

Code:
strSQL = "strSQL = "SELECT * FROM tbManu"
	
	adoRec.Open strSQL, adoCon, adOpenStatic, adLockOptimistic, adCmdText
	adoCon.Execute strSQL

	dbRecordCount = adoRec.RecordCount
	for ix= 1 to dbRecordCount

	response.write("<SELECT>")
	response.write("<option>")&	(adoRec.fields("Manufacturer"))
	response.write("</option>")
	
	
	adoRec.movenext
	next
	response.write("</SELECT>")"

Basicly the table contains car manufacturers and I need this in a drop down box
 
Don't forget to add the value property :

Code:
for ix= 1 to dbRecordCount

	response.write("<SELECT>")
	response.write("<option value="""" & adoRec.fields("Manufacturer") & """" >" & adoRec.fields("Manufacturer"))
	response.write("</option>")
	
	
	adoRec.movenext
	next
	response.write("</SELECT>")"

I've never done ASP before but by my reckoning it would be the above.

I think the triple quotes should put a " in a string.
 
Changed it ever so slightly to this:

Code:
	for ix= 1 to dbRecordCount

	response.write("<SELECT>")
	response.write("<option value=""")& (adoRec.fields("Manufacturer"))& """ >" & (adoRec.fields("Manufacturer"))
	response.write("</option>")

adoRec.movenext
	next
	response.write("</SELECT>")

It works sort of. I have one drop down box with the first option but then instead of having it populated with the options they are written as strings after the combo box. Im guessing its something to do with the for loop
 
Back
Top Bottom