473,408 Members | 2,030 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Need some help with dynamic dropdown in For Loop

I am trying to build a small app that shows a Course Title from the
database, then displays a dropdown full of categories for the user to choose
one...

I thought a loop would be the best way to accomplish this, but since the
dropdown is dynamic, I am having problems. Can someone help me out here?

Here is my code,

For i = 1 to Num
Response.Write("<table width='100%' border='0' cellspacing='0'
cellpadding='0'><tr><td
width='52%'><%=(rsTitles.Fields.Item("Title").Valu e)%></td><td
width='48%'><select name='select'><option value=''>-- Select a
Category --</option><%While (NOT rsTitleCat.EOF)%><option
value='<%=(rsTitleCat.Fields.Item("CatID").Value)% >'><%=(rsTitleCat.Fields.Item("Category").Value)%> </option><%rsTitleCat.MoveNext()
Wend If (rsTitleCat.CursorType > 0) Then rsTitleCat.MoveFirst Else
rsTitleCat.Requery End
If%></select></td></tr><tr><td>&nbsp;</td><td>&nbsp;</td></tr></table>")
Next

Thanks,
Drew
Jul 22 '05 #1
8 1673
Here is some more info... The error I am getting is,

Error Type:
Microsoft VBScript compilation (0x800A03EE)
Expected ')'
/swvtc/DB/Emp/EmpTraining/TitleCategory.asp, line 221, column 126

Line 221 being,

Response.Write("<table width='100%' border='0' cellspacing='0'
cellpadding='0'><tr><td
width='52%'><%=(rsTitles.Fields.Item("Title").Valu e)%></td><td
width='48%'><select name='select'><option value=''>-- Select a
Category --</option><%While (NOT rsTitleCat.EOF)%><option
value='<%=(rsTitleCat.Fields.Item("CatID").Value)% >'><%=(rsTitleCat.Fields.Item("Category").Value)%> </option><%rsTitleCat.MoveNext()
Wend If (rsTitleCat.CursorType > 0) Then rsTitleCat.MoveFirst Else
rsTitleCat.Requery End
If></select></td></tr><tr><td>&nbsp;</td><td>&nbsp;</td></tr></table>")

Column 126 being around,

=(rsTitles.Fields.Item("Title").Value)%

Anyone know what is going on?

Thanks,
Drew

"Drew" <dr********@NOswvtc.dmhmrsas.virginia.SPMgov> wrote in message
news:eS**************@TK2MSFTNGP10.phx.gbl...
I am trying to build a small app that shows a Course Title from the
database, then displays a dropdown full of categories for the user to
choose one...

I thought a loop would be the best way to accomplish this, but since the
dropdown is dynamic, I am having problems. Can someone help me out here?

Here is my code,

For i = 1 to Num
Response.Write("<table width='100%' border='0' cellspacing='0'
cellpadding='0'><tr><td
width='52%'><%=(rsTitles.Fields.Item("Title").Valu e)%></td><td
width='48%'><select name='select'><option value=''>-- Select a
Category --</option><%While (NOT rsTitleCat.EOF)%><option
value='<%=(rsTitleCat.Fields.Item("CatID").Value)% >'><%=(rsTitleCat.Fields.Item("Category").Value)%> </option><%rsTitleCat.MoveNext()
Wend If (rsTitleCat.CursorType > 0) Then rsTitleCat.MoveFirst Else
rsTitleCat.Requery End
If%></select></td></tr><tr><td>&nbsp;</td><td>&nbsp;</td></tr></table>")
Next

Thanks,
Drew

Jul 22 '05 #2
"Drew" <dr********@NOswvtc.dmhmrsas.virginia.SPMgov> wrote in message
news:eS**************@TK2MSFTNGP10.phx.gbl...
I am trying to build a small app that shows a Course Title from the
database, then displays a dropdown full of categories for the user to choose one...

I thought a loop would be the best way to accomplish this, but since the
dropdown is dynamic, I am having problems. Can someone help me out here?

Here is my code,

For i = 1 to Num
Response.Write("<table width='100%' border='0' cellspacing='0'
cellpadding='0'><tr><td
width='52%'><%=(rsTitles.Fields.Item("Title").Valu e)%></td><td
width='48%'><select name='select'><option value=''>-- Select a
Category --</option><%While (NOT rsTitleCat.EOF)%><option
value='<%=(rsTitleCat.Fields.Item("CatID").Value)% >'><%=(rsTitleCat.Fields.I
tem("Category").Value)%></option><%rsTitleCat.MoveNext() Wend If (rsTitleCat.CursorType > 0) Then rsTitleCat.MoveFirst Else
rsTitleCat.Requery End
If%></select></td></tr><tr><td>&nbsp;</td><td>&nbsp;</td></tr></table>")
Next

Thanks,
Drew

Will this help? Watch for word-wrap.

<%
Dim s
s = ""
For i = 1 to Num
s = s & "<table width='100%' border='0' cellspacing='0'
cellpadding='0'>" & vbCrLf
s = s & "<tr>" & vbCrLf
s = s & " <td width='52%'>" & rsTitles("Title") & "</td>" & vbCrLf
s = s & " <td width='48%'>" & vbCrLf
s = s & " <select name='select'>" & vbCrLf
s = s & " <option value=''>-- Select a Category --</option>"
Do Until rsTitleCat.EOF
s = s & " <option value='" & rsTitleCat("CatID") & "'>"
s = s & rsTitleCat("Category") & "</option>" & vbCrLf
rsTitleCat.MoveNext
Loop
If rsTitleCat.CursorType > 0 Then
rsTitleCat.MoveFirst
Else
rsTitleCat.Requery
End If
s = s & " </select>" & vbCrLf
s = s & " </td>" & vbCrLf
s = s & "</tr>" & vbCrLf
s = s & "<tr>" & vbCrLf
s = s & " <td colspan='2'>&nbsp;</td>" & vbCrLf
s = s & "</tr>" & vbCrLf
s = s & "</table>"
s = s & "<br>"
Next
Response.Write(s)
%>
Jul 22 '05 #3
That got me on the right track... I see what you have done there!

Thanks a bunch!
Drew

"McKirahan" <Ne**@McKirahan.com> wrote in message
news:gu********************@comcast.com...
"Drew" <dr********@NOswvtc.dmhmrsas.virginia.SPMgov> wrote in message
news:eS**************@TK2MSFTNGP10.phx.gbl...
I am trying to build a small app that shows a Course Title from the
database, then displays a dropdown full of categories for the user to

choose
one...

I thought a loop would be the best way to accomplish this, but since the
dropdown is dynamic, I am having problems. Can someone help me out here?

Here is my code,

For i = 1 to Num
Response.Write("<table width='100%' border='0' cellspacing='0'
cellpadding='0'><tr><td
width='52%'><%=(rsTitles.Fields.Item("Title").Valu e)%></td><td
width='48%'><select name='select'><option value=''>-- Select a
Category --</option><%While (NOT rsTitleCat.EOF)%><option

value='<%=(rsTitleCat.Fields.Item("CatID").Value)% >'><%=(rsTitleCat.Fields.I
tem("Category").Value)%></option><%rsTitleCat.MoveNext()
Wend If (rsTitleCat.CursorType > 0) Then rsTitleCat.MoveFirst Else
rsTitleCat.Requery End
If%></select></td></tr><tr><td>&nbsp;</td><td>&nbsp;</td></tr></table>")
Next

Thanks,
Drew

Will this help? Watch for word-wrap.

<%
Dim s
s = ""
For i = 1 to Num
s = s & "<table width='100%' border='0' cellspacing='0'
cellpadding='0'>" & vbCrLf
s = s & "<tr>" & vbCrLf
s = s & " <td width='52%'>" & rsTitles("Title") & "</td>" & vbCrLf
s = s & " <td width='48%'>" & vbCrLf
s = s & " <select name='select'>" & vbCrLf
s = s & " <option value=''>-- Select a Category --</option>"
Do Until rsTitleCat.EOF
s = s & " <option value='" & rsTitleCat("CatID") & "'>"
s = s & rsTitleCat("Category") & "</option>" & vbCrLf
rsTitleCat.MoveNext
Loop
If rsTitleCat.CursorType > 0 Then
rsTitleCat.MoveFirst
Else
rsTitleCat.Requery
End If
s = s & " </select>" & vbCrLf
s = s & " </td>" & vbCrLf
s = s & "</tr>" & vbCrLf
s = s & "<tr>" & vbCrLf
s = s & " <td colspan='2'>&nbsp;</td>" & vbCrLf
s = s & "</tr>" & vbCrLf
s = s & "</table>"
s = s & "<br>"
Next
Response.Write(s)
%>

Jul 22 '05 #4
Drew,
Better yet, convert this to using a GetRows array. There is no reason to do
all the requerying etc. Recordset loops are very inefficient. See
www.aspfaq.com for an example (search using the keywords: recordset
iteration ).

Bob Barrows

McKirahan wrote:
<%
Dim s
s = ""
For i = 1 to Num
s = s & "<table width='100%' border='0' cellspacing='0'
cellpadding='0'>" & vbCrLf
s = s & "<tr>" & vbCrLf
s = s & " <td width='52%'>" & rsTitles("Title") & "</td>" &
vbCrLf s = s & " <td width='48%'>" & vbCrLf
s = s & " <select name='select'>" & vbCrLf
s = s & " <option value=''>-- Select a Category --</option>"
Do Until rsTitleCat.EOF
s = s & " <option value='" & rsTitleCat("CatID") & "'>"
s = s & rsTitleCat("Category") & "</option>" & vbCrLf
rsTitleCat.MoveNext
Loop
If rsTitleCat.CursorType > 0 Then
rsTitleCat.MoveFirst
Else
rsTitleCat.Requery
End If
s = s & " </select>" & vbCrLf
s = s & " </td>" & vbCrLf
s = s & "</tr>" & vbCrLf
s = s & "<tr>" & vbCrLf
s = s & " <td colspan='2'>&nbsp;</td>" & vbCrLf
s = s & "</tr>" & vbCrLf
s = s & "</table>"
s = s & "<br>"
Next
Response.Write(s)
%>


--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Jul 22 '05 #5
It should be alright... this app is going to be used for this morning
only... just to get some Titles categorized... nothing else.

Thanks for your reply and I understand what you are saying, I just needed to
throw something together really quickly to save a little time.

Thanks,
Drew

"Bob Barrows [MVP]" <re******@NOyahoo.SPAMcom> wrote in message
news:O0**************@TK2MSFTNGP10.phx.gbl...
Drew,
Better yet, convert this to using a GetRows array. There is no reason to
do
all the requerying etc. Recordset loops are very inefficient. See
www.aspfaq.com for an example (search using the keywords: recordset
iteration ).

Bob Barrows

McKirahan wrote:
<%
Dim s
s = ""
For i = 1 to Num
s = s & "<table width='100%' border='0' cellspacing='0'
cellpadding='0'>" & vbCrLf
s = s & "<tr>" & vbCrLf
s = s & " <td width='52%'>" & rsTitles("Title") & "</td>" &
vbCrLf s = s & " <td width='48%'>" & vbCrLf
s = s & " <select name='select'>" & vbCrLf
s = s & " <option value=''>-- Select a Category --</option>"
Do Until rsTitleCat.EOF
s = s & " <option value='" & rsTitleCat("CatID") & "'>"
s = s & rsTitleCat("Category") & "</option>" & vbCrLf
rsTitleCat.MoveNext
Loop
If rsTitleCat.CursorType > 0 Then
rsTitleCat.MoveFirst
Else
rsTitleCat.Requery
End If
s = s & " </select>" & vbCrLf
s = s & " </td>" & vbCrLf
s = s & "</tr>" & vbCrLf
s = s & "<tr>" & vbCrLf
s = s & " <td colspan='2'>&nbsp;</td>" & vbCrLf
s = s & "</tr>" & vbCrLf
s = s & "</table>"
s = s & "<br>"
Next
Response.Write(s)
%>


--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.

Jul 22 '05 #6
Bob,

With all due respect, I understand your point about recordsets...but I dont
like arrays - it makes the code almost unreadable and it becomes a bitch to
sort out if you ever add/delete a column in the middle of select statement.

Here's the technique that I use:

set ix = Server.CreateObject("MSXML2.DomDocument")
rs.save ix,1
rs.close
set rs = nothing
set nodeList = ix.selectNodes("//z:row")
for each node in nodeList
response.write node.getAttribute("columnName") ' columnName must be same
case as used in SELECT
next

That way I can release the recordset early and I can grab the field by name.

Brian

"Bob Barrows [MVP]" <re******@NOyahoo.SPAMcom> wrote in message
news:O0**************@TK2MSFTNGP10.phx.gbl...
Drew,
Better yet, convert this to using a GetRows array. There is no reason to
do
all the requerying etc. Recordset loops are very inefficient. See
www.aspfaq.com for an example (search using the keywords: recordset
iteration ).

Jul 22 '05 #7
Brian Staff wrote:
Bob,

With all due respect, I understand your point about recordsets...but
I dont like arrays - it makes the code almost unreadable and it
Maybe so (I've gotten used to it - it's not really that much harder), but
you can't beat it for pure performance. Only GetString is faster. The
bottleneck is looping through the recordset, which is a very complex
structure. Especially referring to the fields by name instead of by ordinal
position, which can slow things down quite a bit.

xpath queries are slow as well. I only use xml documents for passing data
across process boundaries (see http://www.davidpenton.com/testsite/tips/).
In the scenario you describe, you may as well disconnect your recordset,
close your connection and utilize your recordset object. IMO, you're not
really gaining anything by converting the recordset to xml and utilizing the
xml document in the same process. I've never compared the performance, so
YMMV.
becomes a bitch to sort out if you ever add/delete a column in the
middle of select statement.

As for new columns, I'm not sure why you'd ever put a new one in the middle
(there is nothing forcing anyone to consume the data in the order in which
they appear in a select statement), but the use of constants can mitigate
the pain (although I use dynamic sql for this illustration, do not take this
as an endorsement of its use).

sSQL = "select colQ, colE, colJ FROM ... "

const colQ = 0
const colE = 1
const colJ = 2

....
arData = rs.GetRows
rs.Close: set rs=nothing
conn.close: set conn = nothing

for iRow = 0 to ubound(arData,2)
response.write "colE contains " & arData(colE, iRow) & "; " & _
response.write "colQ contains " & arData(colQ, iRow) & ...
next

Then, when te statement changes to :

sSQL = "select colQ, colE,colB, colJ FROM ... "

All you need to do is revise the constants:

const colQ = 0
const colE = 1
const colB = 2
const colJ = 3
Bob Barrows
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Jul 22 '05 #8
Bob,

Thanks for the reply. Good points all.

I started using the rs->xml technique when I started to separate the data
retrieval layer from the business logic layer.

Brian

Jul 22 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Newbie1000 | last post by:
Hi all, I have a piece of code that I can't seem to get to work. It compiles OK, but crashes when run :confused: Simplified the code is: Matrix::Matrix(int size){ // Constructor definition...
3
by: John F. | last post by:
Hi all, I'm searching fulltime for days now, and I don't find the solution, so I'm thinking this is more a bug :( If i use following code in form&subforms:
7
by: Jeff Uchtman | last post by:
I know I have done this but my mind is fried. I have a dynamic dropdown in a form. I need to pull both the dynamic dropdown's ID and name listed in the dropdown. Need a little help with grey...
2
NewYorker
by: NewYorker | last post by:
Q1: Given an int variable n that has already been declared and initialized to a positive value, and another int variable j that has already been declared, use a while loop to print a single...
1
by: hjc | last post by:
I am trying to write a program that will give me the number of coins it takes to make up a particular amout. if I write 50 in the command prompt it will say 2 quarters. I have this much and need...
7
by: nicolas | last post by:
hello, i am new to programming... i was looking for some help if anybody can help me here, i'd glady appreciate it. i have to create a for structure where it asks the user to input a certain...
3
by: stressedstudent | last post by:
I dont know where I am going wrong so I dont know which part to post, this is what I have, can anyone help me figure out where I am going wrong? THanks for any and all help. // into to c++ //...
3
Thekid
by: Thekid | last post by:
I need help writing a loop for this. image = ImageGrab.grab((0,0,800,800)) box = (100,100,400,400) im = image.crop(box) im1 = im.save("screen.jpg") # at this point I need to rotate the image...
2
by: raamay | last post by:
I want to have a dynamic dropdown box whose entries would depend on the selection of an entry in the first dropdown box. BUT the second dropdown box should not reload, only the entries inside should...
32
by: falconsx23 | last post by:
I am making a game called Set, it is a card game: here is a brief description of the rules: The game of Set is played with 81 cards, each of which has 4 properties (number, pattern, color and...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.