p2p.wrox.com Forums

Need to download code?

View our list of code downloads.

  Return to Index  

proasp_codeclinic thread: Select box

Message #1 by "Shaukat Desai" <shaukat.desai@g...> on Tue, 5 Sep 2000 15:30:06 +0100
Yes, this creates a duplicate value, because first you add your own, and 
then you let the RS add one.

Try checking the value inside the loop.
Try something like this:

Dim sMyTaxCode
sMyTaxCode = rs("TaxCode") ' choose one of the two. I don't know where you 
get your data from
sMyTaxCode = Request.QueryString("txtTaxCode")

Response.Write("<select name=""TaxCode"" id=""TaxCode"">")
While not rsTaxCode.EOF
         if rsTaxCode("TaxCode") = sMyTaxCode then ' this is the selected item
                 Response.write("<option selected value=""" & 
rsTaxCode("TaxCode") & """>" & rsTaxCode("TaxCode") & "</option>"
                 Response.write("<option value=""" & rsTaxCode("TaxCode") & 
""">" & rsTaxCode("TaxCode") & "</option>"
         end if

You could optimize this a bit by storing rsTaxCode("TaxCode") in a variable 
inside the loop, and use that to do the Response.Write for the option 
element. This should be faster than referencing the Recordset three times.

Hope this helps (and was what you menat)

I haven't tested the above code so I might have overlooked an " or so......


At 03:30 PM 9/5/2000 +0100, you wrote:
>Hi I have two pages Add.asp and Update.asp.  On the Add page I have a
>select box which is populated from a db.
><select name="TaxCode" id="TaxCode">
>       <%
>       While (NOT Recordset1.EOF)
>        %>
>      <option value="<%=Recordset1("TaxCode")%>">
>      <%=Recordset1("TaxCode") >
>      </option>
>      <%Recordset1.MoveNext()
>      Wend%>
>         </select>
>The user selects a value and this is added to the db.  The problem I have
>is when they are on the update page I want to be able to work out which
>option they selected and is stored on the db and display it.  I tried
>doing this but it created a duplicate value.

  Return to Index