|
 |
asp_databases thread: dynamic Drop down
Message #1 by "WVerner" <w_verner@h...> on Sat, 22 Mar 2003 19:07:00
|
|
Good evening all,
i am stil having persisting problems in trying to
figure out how to create a drop down box that gets its
contents from a database table.
the table i have is called Book: BookID, Title, Publisher
What i want to do is create a drop down box that gets all the
titles from the Book table and put them in the drop down.
Ive only started learning ASP since monday so go easy on me guys!
heres the code ive tried to write so far:
<!--#include file="Clssfd.asp"-->
<html>
<head>
<title>Dynamic Drop-Down Menu</title>
</head>
<body>
<%
Dim rsBook
Set rsBook = Server.CreateObject("ADODB.Recordset")
rsBook.Open "Book", objConn, adOpenForwardOnly, adLockOptimistic,
adCmdTable
Do while not rsBook.EOF
Response.write "<OPTION value= "" & Title & ""></OPTION>"
rsBook.MoveNext
Loop
%>
</body>
</html>
Message #2 by Mark Eckeard <meckeard2000@y...> on Sat, 22 Mar 2003 11:10:27 -0800 (PST)
|
|
Try this, although I didn't test it:
<%
Dim rsBook
Dim strSQL
'Set our SQL string.
strSQL = "select BookID, Title, Publisher from Book"
'Create our RS object.
Set rsBook = Server.CreateObject("ADODB.Recordset")
'Open & execute the SQL.
rsBook.Open strSQL, objConn, adOpenForwardOnly,
adLockOptimistic, adCmdTable
'Make sure we have some records before we proceed.
if not rsBook.BOF and not rsBook.EOF then
Do while not rsBook.EOF
Response.write ("<OPTION value= """ &
rsBook("BookID").value & """>" &
rsBook.fields("Title").value & "</OPTION>" & vbcrlf)
rsBook.MoveNext
Loop
end if
'Destroy our RS.
set rsBook = nothing
%>
Watch out for line wrapping!
Mark.
--- WVerner <w_verner@h...> wrote:
> Good evening all,
> i am stil having persisting problems in trying to
> figure out how to create a drop down box that gets
> its
> contents from a database table.
>
> the table i have is called Book: BookID, Title,
> Publisher
>
> What i want to do is create a drop down box that
> gets all the
> titles from the Book table and put them in the drop
> down.
>
> Ive only started learning ASP since monday so go
> easy on me guys!
>
> heres the code ive tried to write so far:
>
> <!--#include file="Clssfd.asp"-->
> <html>
> <head>
> <title>Dynamic Drop-Down Menu</title>
> </head>
>
> <body>
>
> <%
> Dim rsBook
> Set rsBook
> Server.CreateObject("ADODB.Recordset")
> rsBook.Open "Book", objConn, adOpenForwardOnly,
> adLockOptimistic,
> adCmdTable
> Do while not rsBook.EOF
> Response.write "<OPTION value= "" & Title &
> ""></OPTION>"
> rsBook.MoveNext
> Loop
> %>
>
> </body>
> </html>
__________________________________________________
Do you Yahoo!?
Yahoo! Platinum - Watch CBS' NCAA March Madness, live on your desktop!
http://platinum.yahoo.com
Message #3 by "WVerner" <w_verner@h...> on Sat, 22 Mar 2003 19:47:13
|
|
mark, thanks so much...
i included my clssfd file which is a reference to the database just.
im getting this error though?
: Error Type:
Microsoft VBScript compilation (0x800A0411)
Name redefined
/box.asp, line 4, column 4
Dim strSQL
Message #4 by Mark Eckeard <meckeard2000@y...> on Sat, 22 Mar 2003 13:28:23 -0800 (PST)
|
|
Post all your code. We don't know line 4 is.
Is it's a lot of code, feel free to email off-list. I
don't mind helping.
I would recommend getting a good ASP book and pouring
over some of the better ASP sites:
http://www.asp101.com/
http://www.aspin.com/
http://www.learnasp.com/
http://www.aspwire.com/
http://www.aspalliance.com/
http://www.aspfree.com/
http://www.devguru.com/
http://www.w3schools.com/asp/default.asp
http://www.101-asp-tutorials.com/
http://www.4guysfromrolla.com
I think we all have learned a thing or two from these
resources.
Mark
--- WVerner <w_verner@h...> wrote:
> mark, thanks so much...
> i included my clssfd file which is a reference to
> the database just.
>
> im getting this error though?
>
> : Error Type:
> Microsoft VBScript compilation (0x800A0411)
> Name redefined
> /box.asp, line 4, column 4
> Dim strSQL
__________________________________________________
Do you Yahoo!?
Yahoo! Platinum - Watch CBS' NCAA March Madness, live on your desktop!
http://platinum.yahoo.com
Message #5 by "WVerner" <w_verner@h...> on Sun, 23 Mar 2003 11:34:36
|
|
Good morning Mark,
i got some code working there late last night. asp101 gave me
another example which set me on the right road!
just a quickie question: how do you alphabetically order
a list box? :)
thanx for your patience.
Message #6 by Mark Eckeard <meckeard2000@y...> on Sun, 23 Mar 2003 06:15:49 -0800 (PST)
|
|
Glad you were able to get it working.
The easiest way is to ORDER your records as they get
returned from the database.
Change your SQL to this:
Select BookID, BookName
From Books
Order by BookName <-- Sorts your records
Mark.
--- WVerner <w_verner@h...> wrote:
> Good morning Mark,
> i got some code working there late last night.
> asp101 gave me
> another example which set me on the right road!
>
> just a quickie question: how do you alphabetically
> order
> a list box? :)
>
> thanx for your patience.
__________________________________________________
Do you Yahoo!?
Yahoo! Platinum - Watch CBS' NCAA March Madness, live on your desktop!
http://platinum.yahoo.com
Message #7 by "WVerner" <w_verner@h...> on Sun, 23 Mar 2003 15:36:57
|
|
sorted mate! got it all up and running! thanks for your direction an
replies again.
Message #8 by Mark Eckeard <meckeard2000@y...> on Sun, 23 Mar 2003 07:41:07 -0800 (PST)
|
|
Your welcome. Glad I could help.
Mark.
--- WVerner <w_verner@h...> wrote:
> sorted mate! got it all up and running! thanks for
> your direction an
> replies again.
__________________________________________________
Do you Yahoo!?
Yahoo! Platinum - Watch CBS' NCAA March Madness, live on your desktop!
http://platinum.yahoo.com
|
|
 |