pOPULATE COMBOBOX

Discussion in 'C#' started by k6945n, Apr 19, 2006.

  1. #1
    Hi all,

    i have already populate a list from my database using the following code

    <form method=post action="ProcessOrder.asp">
    <select NAME="TEST">
    
     
            <% Do while NOT rsHis.EOF 
            
             	response.write "<OPTION VALUE=' " & rshis("pic_id") & " '> " 
                    response.write rshis("title")
    		 rsHis.MoveNext 
    		loop	%>
    		
    		
    
    </select>
    Code (markup):


    But i dont know how to present the results from the combo box...any sample code would much appreciated
     
    k6945n, Apr 19, 2006 IP
  2. vectorgraphx

    vectorgraphx Guest

    Messages:
    545
    Likes Received:
    16
    Best Answers:
    0
    Trophy Points:
    0
    #2
    i'm a little confused - what are you askind specifically? your code looks like it should work fine as far as building the combo box etc...
     
    vectorgraphx, Apr 20, 2006 IP
  3. DangerMouse

    DangerMouse Peon

    Messages:
    275
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I think you've got confused near your quotes... ;)

    double quotes ("") represent single quotes (") inside the <% a= "xyz" %> asp script tags... where you see 3 in a row - that means that it's quote ("") and end string (")

    try this:

    <select> 
    <% Do while NOT rsHis.EOF 
    response.write "<OPTION VALUE=""" & rshis("pic_id") & """>" 
    response.write rshis("title") & "</OPTION>"
    rsHis.MoveNext 
    loop	
    %>
    </select>
    Code (markup):
    I've also closed the option tag, that's just good practice ;)
     
    DangerMouse, Apr 20, 2006 IP
  4. vectorgraphx

    vectorgraphx Guest

    Messages:
    545
    Likes Received:
    16
    Best Answers:
    0
    Trophy Points:
    0
    #4
    both suggestions are good - but i'm still confused as to what he was asking, because the option tag should have worked with apostrophes instead of quotes even though it's better practice to do it your way, and as you said the closing of the option tag is optional -

    /methinks this may be yet another one of those mysterious random users that shows up and posts a relatively obfuscated question and never comes back... leaving us to ponder... what does it all mean?

    hmmm....
     
    vectorgraphx, Apr 21, 2006 IP
  5. k6945n

    k6945n Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    hi all again... i am not mysterious random user...just had a job to finish and i didnt have time to respond...sorry for that...

    in my question now... sorry if i confuse you... my english is not very well... Well i am trtying to say is that although... the above script works fine I dont know how can I show the results of this code to the page i set it (ProcessOrder.asp)...what kind of code should i use???...

    One more question... i would like to see not only the pic_id from the database but and a title (description) next to it...is it possible and how???

    thank you
     
    k6945n, Apr 21, 2006 IP
  6. k6945n

    k6945n Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    lets give an example...from a combo box i select an item and would return me a number (pic_id)...lets say 10... i dont want to see only the number 10 but also a title/description of that...lets say "the number you choose is:" 10
     
    k6945n, Apr 21, 2006 IP
  7. vectorgraphx

    vectorgraphx Guest

    Messages:
    545
    Likes Received:
    16
    Best Answers:
    0
    Trophy Points:
    0
    #7
    ok, for that, you would do something like:

    pic_id - request.form("pic_id")

    response.write "the number you choose is: " & pic_id

    you would also need to name your select element on the form page - i.e.


    <select name = "pic_id" >
    <% Do while NOT rsHis.EOF
    response.write "<OPTION VALUE=""" & rshis("pic_id") & """>"
    response.write rshis("title") & "</OPTION>"
    rsHis.MoveNext
    loop
    %>
    </select>
     
    vectorgraphx, Apr 21, 2006 IP
  8. DangerMouse

    DangerMouse Peon

    Messages:
    275
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #8
    You can't return the label from a select box so you'll have to do another query if you want to write it back to the page...

    If a user submits the form - and you want to remember selection?

    <select name = "pic_id" >
    <% Do while NOT rsHis.EOF
    response.write "<OPTION VALUE=""" & rshis("pic_id") & "" "
    If CInt(request.form("pic_id")) = rshis("pic_id") Then
    response.write "SELECTED"
    End If
    response.write ">"
    response.write rshis("title") & "</OPTION>"
    rsHis.MoveNext
    loop
    %>
    </select>

    that should do it?
     
    DangerMouse, Apr 22, 2006 IP