Select List Box from Array

Discussion in 'ASP General' started by dthmtlgod, Dec 16, 2005.

  1. dthmtlgod

    dthmtlgod Guest

    I have a string that was populated from a listbox.
    Now I want to bring up the record again for edit and want the listbox to
    have those records selected ONLY. I am close I think. Currently, it
    selects all records.

    <%
    HearingIssues = RS3(0)
    HI = Split(HearingIssues, ",", -1, 1)

    For i = 0 to ubound(HI,1)
    sString = Instr(HearingIssues,HI(I))
    if sString = 0 then
    %>
    <option value="<%= HI(I)%>"><%=HI(I) %></option>
    <% else %>
    <option value="<%= HI(I)%>" selected><%= HI(I) %></option>
    <% end if
    next
     
    dthmtlgod, Dec 16, 2005
    #1
    1. Advertising

  2. dthmtlgod

    Larry Bud Guest


    > I have a string that was populated from a listbox.
    > Now I want to bring up the record again for edit and want the listbox to
    > have those records selected ONLY. I am close I think. Currently, it
    > selects all records.
    >
    > <%
    > HearingIssues = RS3(0)
    > HI = Split(HearingIssues, ",", -1, 1)
    >
    > For i = 0 to ubound(HI,1)
    > sString = Instr(HearingIssues,HI(I))
    > if sString = 0 then
    > %>
    > <option value="<%= HI(I)%>"><%=HI(I) %></option>
    > <% else %>
    > <option value="<%= HI(I)%>" selected><%= HI(I) %></option>
    > <% end if
    > next%>


    I don't see your <SELECT> tag, are you allowing multiple select?

    where it says "selected" you need to see if HI(I) is INSTR your
    variable, and if it is, response.write("selected")
     
    Larry Bud, Dec 16, 2005
    #2
    1. Advertising

  3. dthmtlgod

    dthmtlgod Guest

    Here is the code with the SELECT statement. It is still selecting the
    entire list box.


    <select name="HearingIssues" size="11" multiple style="width: 250px;">
    <%
    While NOT RS3.EOF
    HearingIssues = RS3(0)
    HI = Split(HearingIssues, ",", -1, 1)

    For i = 0 to ubound(HI,1)
    sString = Instr(HearingIssues,HI(I))
    if sString = 0 then
    %>
    <option value="<%= HI(I)%>"><%=HI(I) %></option>
    <% else %>
    <option value="<%= HI(I)%>" selected><%= HI(I) %></option>
    <%
    end if
    next

    RS3.MoveNext
    WEND
    %>
    </select>

    "Larry Bud" <> wrote in message
    news:...
    >
    > > I have a string that was populated from a listbox.
    > > Now I want to bring up the record again for edit and want the listbox to
    > > have those records selected ONLY. I am close I think. Currently, it
    > > selects all records.
    > >
    > > <%
    > > HearingIssues = RS3(0)
    > > HI = Split(HearingIssues, ",", -1, 1)
    > >
    > > For i = 0 to ubound(HI,1)
    > > sString = Instr(HearingIssues,HI(I))
    > > if sString = 0 then
    > > %>
    > > <option value="<%= HI(I)%>"><%=HI(I) %></option>
    > > <% else %>
    > > <option value="<%= HI(I)%>" selected><%= HI(I) %></option>
    > > <% end if
    > > next%>

    >
    > I don't see your <SELECT> tag, are you allowing multiple select?
    >
    > where it says "selected" you need to see if HI(I) is INSTR your
    > variable, and if it is, response.write("selected")
    >
     
    dthmtlgod, Dec 19, 2005
    #3
  4. dthmtlgod

    Larry Bud Guest

    dthmtlgod wrote:
    > Here is the code with the SELECT statement. It is still selecting the
    > entire list box.
    >
    >
    > <select name="HearingIssues" size="11" multiple style="width: 250px;">
    > <%
    > While NOT RS3.EOF
    > HearingIssues = RS3(0)
    > HI = Split(HearingIssues, ",", -1, 1)
    >
    > For i = 0 to ubound(HI,1)
    > sString = Instr(HearingIssues,HI(I))
    > if sString = 0 then
    > %>
    > <option value="<%= HI(I)%>"><%=HI(I) %></option>
    > <% else %>
    > <option value="<%= HI(I)%>" selected><%= HI(I) %></option>
    > <%
    > end if
    > next
    >
    > RS3.MoveNext
    > WEND
    > %>
    > </select>


    You need to debug in steps:
    It would be selecting every entry in the select box if the "if
    sString=0" statement is always false.

    So let's look at sString. It's set with Instr function:
    sString = Instr(HearingIssues,HI(I))

    We know sString is always being set to a non-zero, right? A non zero
    occurs when 1) the first string is null, 2) the second string is null,
    or string2 is found within string1.

    So how about printing out the values for hearingissues, and HI(i)??

    Also, why are you using Instr? When you're looping through your
    recordset, aren't you looping through all possible single values for
    hearingissues?
     
    Larry Bud, Dec 21, 2005
    #4
    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. Gnarlodious
    Replies:
    4
    Views:
    17,642
    elizas
    May 5, 2010
  2. Robin
    Replies:
    2
    Views:
    179
    Robin
    Apr 9, 2004
  3. Sy Ys
    Replies:
    0
    Views:
    134
    Sy Ys
    Sep 15, 2007
  4. palmiere
    Replies:
    1
    Views:
    431
    Erwin Moller
    Feb 9, 2004
  5. Ferd Berfel
    Replies:
    4
    Views:
    158
Loading...

Share This Page