Search Search

#1 worldwide
FREE Coding Lessons

since 1996
   THE BEST WAY to learn ASP & Asp.net!
Advertise Here!
click for details
Credits Host:
DiscountASP.net
Server Admin:
The "Team"
Contact Info.
Charles M. Carroll

my Blog

HTML List Box from Column

This page demonstrates the capabilities how to display a list box from a SQL statement. This is the simplest possible example. The script to display a list from a database is:

   filename=/learn/test/dblist.asp

<Test Script Below>


<html><head>
<TITLE>dblist.asp</TITLE>
</head><body bgcolor="#FFFFFF">
<% 
myDSN="DSN=Student;uid=student;pwd=magic"
mySQL="select author from authors where AU_ID<100"

' displays a database field as a listbox
set conntemp=server.createobject("adodb.connection")
conntemp.open myDSN
set rstemp=conntemp.execute(mySQL)
if rstemp.eof then
    response.write "no data for<br>"
    response.write mySQL
    conntemp.close
    set conntemp=nothing
    response.end        
end if

%>
<form action="dblistrespond.asp" method="post">
<Select name="authorname">
<%
' Now lets grab all the data
do until rstemp.eof %>
    <option> <%=RStemp(0)%> </option>
    <%
    rstemp.movenext
loop

rstemp.close
set rstemp=nothing
conntemp.close
set conntemp=nothing
%>
<input type="submit" value="Choose Author">
</Select></form>
</body></html>

The form responder dblistrespond.asp is:
   filename=/learn/test/dblistrespond.asp

<Test Script Below>


<html><head>
<TITLE>dblistrespond.asp</TITLE>
</head><body bgcolor="#FFFFFF">
<%
my_author=request.form("authorname")
%>
You choose <%=my_author%><br>Thanks!<br>
</body></html>

Chaz Wish List
Tall Tip $5
Grande Tip $20
Venti Tip $39
Tip Jar Thanks
2004 Thanks
2005 Thanks
HUGE Tip -love site