SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Member
    Join Date
    Sep 2013
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Classic asp Display Multi selected list box values

    Hi

    My issues is I am not able to display the multi selected list box values.I could display single value if single value is selected.Please help me on this.

    Here is my code:

    'To display Client in dropdown
    Set objConn = Server.CreateObject("ADODB.Connection")
    objConn.Open Application("conn")
    Set oRs = Server.CreateObject("ADODB.Recordset")
    dstrSQL="select Name from Client order by Name"
    oRs.Open dstrSQL, objConn, 1,3
    'Error Handling Part
    If Err.Number <> 0 Then
    Response.Buffer = True
    Response.Redirect "ShowError.asp?ErrNum=" & Err.number & "&ErrSource=" & Err.source & "&ErrDesc=" & Err.description
    End If
    On Error GoTo 0
    'End Error Handling Part

    WHILE NOT oRs.EOF

    if Request.QueryString("Postback") = "true" and trim(oRs("Name")) = trim(request("ddlClient")) then
    ProjClient = ProjClient & "<option selected value=""" & oRs("Name") & """>" & oRs("Name") & "</option>"
    ELSE
    ProjClient = ProjClient & "<option value=""" & oRs("Name") & """>" & oRs("Name") & "</option>"
    END IF
    oRs.MoveNext
    WEND
    oRs.Close
    objConn.Close
    set oRs = nothing
    Set objConn = nothing

  2. #2
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,631
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    You don't show your HTML for the Select list ... have you set that as a Multiselect type?
    Ian Anderson
    www.siteguru.co.uk

  3. #3
    SitePoint Member
    Join Date
    Sep 2013
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Post I forgot to mention here the html part of code.

    Quote Originally Posted by siteguru View Post
    You don't show your HTML for the Select list ... have you set that as a Multiselect type?
    Yes I have used Multipselect type .Here is my html for listbox

    <select size="6" name="ddlClient" multiple="multiple">
    <%=ProjClient%>
    </select>

    I am saving the Client as commaseperated values in the db.I have to compare the comma seperated values with each listbox item to select the multiple list items.

  4. #4
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,631
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Ah. I suspect your problem is that you need to split() the oRS("Name") on the comma character. When only one item exists then oRS("Name") equals the value; when more than one exists then oRS("Name") contains a comma:

    One name selected - oRS("Name")="Bob"
    Two names selected - oRS("Name")="Bob,John"

    So your code as it stands will never find a match.
    Ian Anderson
    www.siteguru.co.uk

  5. #5
    SitePoint Member
    Join Date
    Sep 2013
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Need solution to display multiple selected values in list box

    Quote Originally Posted by siteguru View Post
    Ah. I suspect your problem is that you need to split() the oRS("Name") on the comma character. When only one item exists then oRS("Name") equals the value; when more than one exists then oRS("Name") contains a comma:

    One name selected - oRS("Name")="Bob"
    Two names selected - oRS("Name")="Bob,John"

    So your code as it stands will never find a match.

    Can some one get me the solution to displat multiple selected values in listbox ???

  6. #6
    SitePoint Enthusiast
    Join Date
    Aug 2011
    Location
    OH, USA
    Posts
    72
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    did you check you html in browser? just right click and view page source...
    it looks like your problem there
    if Request.QueryString("Postback") = "true" and trim(oRs("Name")) = trim(request("ddlClient")) then
    first part clear and no questions Request.QueryString("Postback") = "true"
    second part is a question trim(oRs("Name")) = trim(request("ddlClient")
    what you expect to have in trim(request("ddlClient") ? and what should be in trim(oRs("Name"))?
    if your select box has <option value = '1' selected>first</option>
    <option value = '2'>second</option>
    <option value = '3' selected>third</option>
    <option value = '4'>forth</option>
    in trim(request("ddlClient") you should have 1,3
    do you have value of 1,3 in trim(oRs("Name")) - I do not think so... and this is one problem and even of yes which item to mark selected it is no item with value 1,3...
    So what you should do split 1,3 in array a= split( trim(request("ddlClient")),",") and search value inside array a
    like
    for i=0 to ubound(a)
    if a(i) = trim(oRs("Name")) then
    found = true
    end if
    next

  7. #7
    SitePoint Member
    Join Date
    Sep 2013
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you gk53 .Yes I should use split with arrays for desired results.
    I finally got my results with following function use

    function CheckExistsfunc(namevalue1,Namevalues)

    arrClient=split(Namevalues,",")
    for i=0 to uBound(arrClient)
    if instr(namevalue1,arrClient(i)) > 0 then
    CheckExistsfunc = CheckExistsfunc & "<option selected value=""" & arrClient(i) & """>" & arrClient(i) & "</option>"
    else
    CheckExistsfunc = CheckExistsfunc & "<option value=""" & arrClient(i) & """>" & arrClient(i) & "</option>"
    end if
    next
    end function

    and I used this function somthing like below :

    <%
    Set objConn1 = Server.CreateObject("ADODB.Connection")
    objConn1.Open Application("conn")
    Set oRs1 = Server.CreateObject("ADODB.Recordset")
    dstrSQL="select Name from Client order by Name"
    oRs1.Open dstrSQL, objConn1, 1,3
    'Error Handling Part
    If Err.Number <> 0 Then
    Response.Buffer = True
    Response.Redirect "ShowError.asp?ErrNum=" & Err.number & "&ErrSource=" & Err.source & "&ErrDesc=" & Err.description
    End If
    On Error GoTo 0
    'End Error Handling Part
    dim selectedClient
    dim Client
    WHILE NOT oRs1.EOF
    Client1=Client1 & oRs1("Name") & ","
    oRs1.MoveNext
    session("Client1")=ClientData
    WEND
    if request.QueryString("Postback") = "true" then

    Client=CheckExistsfunc(request("Client"),session("Client1"))
    else
    Client=CheckExistsfunc(objRS.fields("Client"),Client1)
    end if
    oRs1.Close
    objConn1.Close
    set oRs1 = nothing
    Set objConn1 = nothing
    %>
    <select multiple="multiple" name="Client" size="6">
    <%=Client%>
    </select>


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •