|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Dropdown mayhem!
Hello all, quick question here...its been boggling my mind and my heads hurting!
I've been coding my own ASP scripts lately, just started...however none of the 3 books I bought cover MSSQL and ASP integration when it comes to creating dropdown lists...most people reading this are probably laughing already and saying "Damn this guy's a noob!" But we all gotta start out somewhere Anyhow, I've been trying to get something together for almost a week now...I've just about given up totally and I'm just looking for what people would do code wise to create such a thing to help guide me on my way. Pretty basic...Just a dropdown that reads from a MSSQL server...in which I can point it to a certain ID / table column to get the potential "list" from. Alphabetize that, and then store that selected item to another table / column which is pre-existing. Any help would be greatly appreciated...Im just looking for a script I follow to help me out a little. Thanks fellas / gals ![]() |
|
#2
|
||||
|
||||
|
This is a simple script to generate a dynamic dropdown. You will need to alter based on your own database.
Code:
<% 'Set connection
set conn=server.createobject("ADODB.Connection")
'Set Recordset
set rs=server.createobject("ADODB.Recordset")
'Open connection
conn.open "Driver={SQL Server};Server=server1;Database=mydb;Uid=sa;Pwd=;" %>
<!-- HTML code -->
<select name="dropdown1" size="1">
<%
'setup sql query
strsql = "SELECT id,description FROM table1"
'open recordset with query
rs.open strsql,conn
'loop through records returned until End of File
do until rs.eof
'write id and description as an option in dropdown
response.write("<option value="""&rs("id")&""">"&rs("description")&"</option>")
'move to next record
rs.movenext
'return to do
loop
%>
<!-- HTML code -->
</select>
<%
'close recordset
rs.close
'close connection
conn.close
'tidy up objects
set rs=nothing
set conn=nothing
%>
To retrieve the value, use:- request.form("dropdown1") Hope that helps.
__________________
Policy Check I'd rather have a full bottle in front of me, than a full frontal lobotomy...
|
![]() |
| Viewing: ASP Free Forums > Other > Programming Help > Dropdown mayhem! |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|