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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

combo box multiple selection

Status
Not open for further replies.

neerajam

Technical User
Mar 4, 2002
23
0
0
US
I am a newbie to ASP programming. I would like my multiple selections in a combo box to remain selected. I have a combo box that is populated with a do while not recordset.eof/Loop statement. I did give it a try with a for /next loop(from i = 1 to Request.Form("showdata").count. But I always selected only the first selection, not the subsequent ones. Where did I go wrong.
 
Show us your for /next loop.

Does it look something like this?

Response.Write &quot;<select name=bleh multiple>&quot;
For i = 1 To Request.Form(&quot;showdata&quot;).Count
Response.Write &quot;<option value=thisoption&quot;
If Request.Form(&quot;showdata&quot;)(i) = &quot;thisoption&quot; Then
Response.Write &quot; selected&quot;
End If
Response.Write &quot;>thisoption</option>&quot;
Next
Response.Write &quot;</select>&quot;
 
My code is as follows:
<%
sql = sql & &quot;SELECT top 40 show_i, show_nm, start_dt from show order by start_dt DESC&quot;
set rs = conn.execute(sql)
For i = 1 to request.form(&quot;showdata&quot;).count
do while not rs.eof
sselected = &quot;&quot;
If (CSTR(rs.fields(&quot;show_i&quot;))= request.form(&quot;showdata&quot;) then sselected = &quot;SELECTED&quot;%>
<option <%=sselected%> value = <%=rs.fields(&quot;show_i&quot;)%>>rs.fields(&quot;show_nm&quot;) & &quot; &quot; & rs.fields(&quot;start_dt&quot;)%></option>
<%
rs.movenext
Loop
Next
%>
</SELECT>

This is what I have. Only the first selection is being selected.

Thanks for the prompt response.
 
Try This...
<%
For i = 1 to request.form(&quot;showdata&quot;).count
do while not rs.eof
sselected = &quot;&quot;
If (CSTR(rs.fields(&quot;show_i&quot;))= request.form(&quot;showdata&quot;)(i) then
sselected = &quot;SELECTED&quot;
End If
Response.Write &quot;<option &quot; & sselected &&quot; value = &quot;& rs.fields(&quot;show_i&quot;) & &quot;>&quot; & rs.fields(&quot;show_nm&quot;) & &quot; &quot; & rs.fields(&quot;start_dt&quot;) &&quot;</option>&quot;
rs.movenext
Loop
Next
%>
 
Used your suggestion. I am getting an error saying Loop without the Do. Everything looks perfectly logical but yet does not want to work.
 
<%
Dim i, sselected
Do While NOT rs.eof
For i = 1 To Request.Form(&quot;showdata&quot;).Count
sselected = &quot;&quot;
If (CSTR(rs.Fields(&quot;show_i&quot;).Value) = Request.Form(&quot;showdata&quot;)(i) Then
sselected = &quot;SELECTED&quot;
'We found a match, so we exit the looping Reques.Form Array
'and continue processing the rest of the RS.
Exit For
End If
Next
Response.Write &quot;<option &quot; & sselected &&quot; value = &quot;& rs.fields(&quot;show_i&quot;) & &quot;>&quot; & rs.fields(&quot;show_nm&quot;) & &quot; &quot; & rs.fields(&quot;start_dt&quot;) &&quot;</option>&quot;
rs.movenext
Loop
%>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top