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

List control and select issue

Status
Not open for further replies.

tman135

Programmer
Feb 28, 2001
48
US
I've got a list control on my ASP page that draws it recordset from a stored procedure in SQl Server database. I want to look at the value in one of the recordset fields and compare it against each value in the list box. If the two are equal, I want to set the list control so that the value is selected, but still show the rest of the recordset.

Here's my code
Code:
<select name=&quot;cmbponds&quot;>
<%
While (NOT rsponds.EOF)
response.write(&quot;<option &quot;)
varPond = rseditfeed.Fields.Item(&quot;pond&quot;).Value
if cstr(cmbponds) = varPond then response.write(&quot;selected &quot;) end if
response.write(&quot;value=&quot;&quot;&quot; & varPond & &quot;&quot;&quot;>&quot; & rsponds.Fields.Item(&quot;pond&quot;).Value & 		 &quot;</option>&quot;)
rsponds.MoveNext()
                  
Wend

I get the entire recordset to load in the list, but the select doesn't.

Any thoughts?
 
OK. You're using some methods that I'm not used to, but after studying your code, I have to assume that rsponds and rseditfeed are valid recordsets. rsponds is looping through records while rseditfeed is staying on a single record and being used to compare against each record in rsponds as it loops to provided a selected parameter.

With that in mind, the only other thing that confused me was that your values for each option are set to reflect a value that does not change since it's based on rseditfeed. I'm going to correct that and if I'm wrong, just put it back the way you want it.

Here's how I would accomplish what you want.


<select name=&quot;cmbponds&quot;>
<%
dim m
dim varPond
WHILE NOT rsponds.EOF
m = &quot; &quot;
'THAT'S A SINGLE WHITE SPACE
varPond = Trim(rsponds(&quot;pond&quot;))
IF varPond = Trim(rseditfeed(&quot;pond&quot;)) THEN
m = &quot; selected &quot;
'LEADING AND TRAILING WHITE SPACE
END IF
%>
<option<%=m%>value=&quot;<%=varPond%>&quot;><%=varPond%></option>
<%
rsponds.MoveNext
WEND
%>
</select>


Hope this helps ..

ToddWW :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top