Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

populate dropdown using getrows 1

Status
Not open for further replies.

w11z

Programmer
Mar 26, 2001
40
0
0
CA
Hello everyone,

I'm trying to populate a dropdown list using the GetRows:

varSQL = "SELECT * FROM dbTable"
Set dbReponse = Server.CreateObject("ADODB.Recordset")
dbReponse.Open varSQL, dbLink

lingAbTab = dbReponse.GetRows()

<select size=&quot;1&quot; name=&quot;readEn&quot;>
<option value=&quot;0&quot; selected>-</option>
<%
For iRowLoop = 0 to UBound(lingAbTab, 2)
For iColLoop = 0 to UBound(lingAbTab, 1)
if (iColLoop = 0) then
aff = &quot;<option value=&quot; & lingAbTab(iColLoop, iRowLoop) & &quot;>&quot;
Else if (iColLoop = 1) then
aff = aff & lingAbTab(iColLoop, iRowLoop) & &quot;</option>&quot;
End if
Next
Response.Write(aff)
Next
%>
</select>

The result should be:

1- yes
2- no
3- maybe
etc.

The error I get is: Unexpected 'Next' (After the End If)

Can someone help me?

Thanks
 
change:
Else if (iColLoop = 1) then

to:

Elseif (iColLoop = 1) then

VBScript/ASP use &quot;elseif&quot; Javascript uses &quot;else if&quot;


MrGreed

&quot;did you just say Minkey?, yes that's what I said.&quot;
 
You'll want to remove the open &quot;(&quot; and close &quot;)&quot; from the if statements also.

MrGreed

&quot;did you just say Minkey?, yes that's what I said.&quot;
 
Thank you very much MrGreed... Sometimes solutions are to easy to find.
 
you might be able to clean this up a bit by changing this:

Code:
For iRowLoop = 0 to UBound(lingAbTab, 2)
 For iColLoop = 0 to UBound(lingAbTab, 1)
  if (iColLoop = 0) then
    aff = &quot;<option value=&quot; & lingAbTab(iColLoop, iRowLoop) & &quot;>&quot;
  Else if (iColLoop = 1) then
    aff = aff & lingAbTab(iColLoop, iRowLoop) & &quot;</option>&quot;
  End if
 Next
  Response.Write(aff)
Next

to this:

Code:
For iRowLoop = 0 to UBound(lingAbTab, 2)
    Response.Write &quot;<option value=&quot;&quot;&quot; & lingAbTab(0, iRowLoop) & &quot;&quot;&quot;>&quot; & lingAbTab(1, iRowLoop) & &quot;</option>&quot;
Next

please note in the above snippet, to ignore any linebreaks as the Response.Write statement should all be on one line!

also notice that two consecutive quote marks lets you output an &quot;un-escaped&quot; quote mark inside a string.

best of luck!
-f!
 
Thanks Funka! I will try it your way. Always looking to optimise the code.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top