dynamic multiple select list not selecting properly

Discussion in 'ASP General' started by Chris, Apr 23, 2004.

  1. Chris

    Chris Guest

    Hi,
    I have a multiple select list I use to display categories with. Each
    product can have multiple categories. So I used a multiple select
    list to accomplish this. The comma delimited string is then split and
    each value is stored in the database separately. The problem is in
    order to edit this product I have to display the product's chosen
    categories somehow. I chose a multiple select list to do this. And
    it won't select anything. What it's supposed to do is this - Loop
    through the rsCats recordset to populate the select list, then within
    that loop, loop through the rsCheck recordset to see if any of the
    values match the rsCats recordset, if it matches output "selected".
    The code I used is below:

    <form>
    <select name="CatID" size="8" multiple>
    <%
    'populate the multiple list
    do until rsCats.eof
    intValue=rsCats("dc_CatID")
    strName=rsCats("dc_CatName")
    intFlag=0
    'loop through the recordset to see if values match
    do until rsCheck.eof or intFlag=1
    if intValue=rsCheck("cad_CatID") then
    strSelected=" selected"
    intFlag=1
    else
    strSelected=" not" 'this is to see the html output
    end if
    rsCheck.movenext()
    loop
    %>
    <option value="<%=intValue%>"<%=strSelected%>><%=strName%></option>
    <%
    rsCats.movenext()
    loop
    %>
    </select>
    </form>
     
    Chris, Apr 23, 2004
    #1
    1. Advertising

  2. Chris

    Alan Howard Guest

    I've seen these comparisons fail if your variants have different subtypes.
    Try assigning rsCheck("cad_CatID") to a local variable and then echoing out
    the types of the two variables in question, intValue and the new one, to
    see - use TypeName(). If this is the problem then cast the two to a common
    subtype before comparing, CStr or CLng for example.

    Alan

    "Chris" <> wrote in message
    news:...
    > Hi,
    > I have a multiple select list I use to display categories with. Each
    > product can have multiple categories. So I used a multiple select
    > list to accomplish this. The comma delimited string is then split and
    > each value is stored in the database separately. The problem is in
    > order to edit this product I have to display the product's chosen
    > categories somehow. I chose a multiple select list to do this. And
    > it won't select anything. What it's supposed to do is this - Loop
    > through the rsCats recordset to populate the select list, then within
    > that loop, loop through the rsCheck recordset to see if any of the
    > values match the rsCats recordset, if it matches output "selected".
    > The code I used is below:
    >
    > <form>
    > <select name="CatID" size="8" multiple>
    > <%
    > 'populate the multiple list
    > do until rsCats.eof
    > intValue=rsCats("dc_CatID")
    > strName=rsCats("dc_CatName")
    > intFlag=0
    > 'loop through the recordset to see if values match
    > do until rsCheck.eof or intFlag=1
    > if intValue=rsCheck("cad_CatID") then
    > strSelected=" selected"
    > intFlag=1
    > else
    > strSelected=" not" 'this is to see the html output
    > end if
    > rsCheck.movenext()
    > loop
    > %>
    > <option value="<%=intValue%>"<%=strSelected%>><%=strName%></option>
    > <%
    > rsCats.movenext()
    > loop
    > %>
    > </select>
    > </form>
     
    Alan Howard, Apr 24, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Thomas 'Skip' Hollowell
    Replies:
    3
    Views:
    1,416
    David W. Burhans
    May 21, 2004
  2. Replies:
    2
    Views:
    344
  3. Vikash Kumar
    Replies:
    2
    Views:
    154
    Alex Young
    Dec 20, 2006
  4. palmiere
    Replies:
    1
    Views:
    432
    Erwin Moller
    Feb 9, 2004
  5. Replies:
    3
    Views:
    102
Loading...

Share This Page