|
 |
asp_web_howto thread: Code to fill combo boxes from a table
Message #1 by "John Howe" <johnhowe@c...> on Thu, 17 Oct 2002 15:18:56
|
|
I am tring to fill a list or combo box dynamically from a table with the
following code.
<%
' Create and open ADO Connection object.
Set cnItems = Server.CreateObject("ADODB.Connection")
cnStItems = "driver={Microsoft Access Driver (*.mdb)};" & _
"dbq=" & Server.MapPath("../Pronto/Items.mdb")
cnItems.Open cnStItems,"",""
' Create and open ADO Recordset object.
Set rsCat = Server.CreateObject("ADODB.Recordset")
sql = "SELECT * FROM categories ORDER BY catdesc ; "
rsCat.Open sql, cnItems, adOpenStatic, adLockReadOnly
' Loop through recordset object, displaying each record.
%>
<SELECT NAME="Category" SIZE="5">
<%
Do While Not rsCat.EOF
%>
<OPTION VALUE = rsCat("catnr") > rscat("catdesc")
<%
rsCat.MoveNext
Loop
%>
</SELECT>
<%
' Close and destroy the recordset and connection objects.
rsCat.Close
Set rsCat = Nothing
cnItems.Close
Set cnItems = Nothing
%>
All I get in the list box is rscat("catdesc"). What am I doing wrong.
Message #2 by "phil griffiths" <pgtips@m...> on Thu, 17 Oct 2002 15:23:55
|
|
>...What am I doing wrong.
You've missed the asp delimiters around the rs("..."). You want
<option value="<%=rs("fieldname")%>">.
(N.B. put quotes around the value just in case there are spaces in the
recordset field. I suppose you should also HTMLEncode it too...)
hth
Phil
Message #3 by "Drew, Ron" <RDrew@B...> on Thu, 17 Oct 2002 11:21:47 -0400
|
|
I think you are missing the asp bookends, quote marks and the =3D sign
<OPTION VALUE =3D "<%=3D rsCat("catnr")%>" > <%=3Drscat("catdesc")%>
-----Original Message-----
From: John Howe [mailto:johnhowe@c...]
Sent: Thursday, October 17, 2002 11:19 AM
To: ASP Web HowTo
Subject: [asp_web_howto] Code to fill combo boxes from a table
I am tring to fill a list or combo box dynamically from a table with the
following code.
<%
' Create and open ADO Connection object.
Set cnItems =3D Server.CreateObject("ADODB.Connection")
cnStItems =3D "driver=3D{Microsoft Access Driver (*.mdb)};" & _
"dbq=3D" & Server.MapPath("../Pronto/Items.mdb")
cnItems.Open cnStItems,"",""
' Create and open ADO Recordset object.
Set rsCat =3D Server.CreateObject("ADODB.Recordset")
sql =3D "SELECT * FROM categories ORDER BY catdesc ; "
rsCat.Open sql, cnItems, adOpenStatic, adLockReadOnly
' Loop through recordset object, displaying each record.
%>
<SELECT NAME=3D"Category" SIZE=3D"5">
<%
Do While Not rsCat.EOF
%>
<OPTION VALUE =3D rsCat("catnr") > rscat("catdesc")
<%
rsCat.MoveNext
Loop
%>
</SELECT>
<%
' Close and destroy the recordset and connection objects. rsCat.Close
Set rsCat =3D Nothing cnItems.Close Set cnItems =3D Nothing %>
All I get in the list box is rscat("catdesc"). What am I doing wrong.
---
Improve your web design skills with these new books from Glasshaus.
Usable Web Menus
http://www.amazon.com/exec/obidos/ASIN/1904151027/ref=3Dnosim/theprogramm
e
r-20
Constructing Accessible Web Sites
http://www.amazon.com/exec/obidos/ASIN/1904151000/ref=3Dnosim/theprogramm
e
r-20
Practical JavaScript for the Usable Web
http://www.amazon.com/exec/obidos/ASIN/1904151051/ref=3Dnosim/theprogramm
e
r-20
|
|
 |