www.webdeveloper.com
Results 1 to 7 of 7

Thread: Classic ASP Select (Combo Box)

  1. #1
    Join Date
    Jan 2007
    Posts
    8

    Classic ASP Select (Combo Box)

    I have a record set with fieldNames and fieldIDs and I would like to populate a Select (comboBox/DropDownList) and I'm not sure how to do it (I normally use ASP.Net).

    I just simple want the user to be able to see the fieldName (IE: rsRecordSet.FieldName) when they click on the comboBox, but I dont know the syntax to do this. So far I have the following code:

    <CODE>

    <SELECT NAME="FieldD">
    <%

    While not rsRecordSet.EOF
    %>
    <OPTION VALUE="<%=rsRecordSet("FieldID")%>"></OPTION>
    <%
    rsRecordSet.MoveNext
    Wend
    If rsRecordSet.State = adStateOpen Then rsRecordSet.Close
    Set rsRecordSet= nothing
    %>
    </SELECT>

    </CODE>

    Thanks!!

  2. #2
    Join Date
    Jul 2004
    Posts
    300
    Not sure I understand, and maybe you can clarify. You want the field name, but you are referencing the element by field name? Why not just have the text in the field, like this:

    <OPTION VALUE="FieldID"></OPTION>

    Or were you trying for something like this:

    <OPTION VALUE="<%=rsRecordSet(columnno).fieldname%>"></OPTION>

    Where columno is the number of the column you want to get the fieldname for.

  3. #3
    Join Date
    Jan 2007
    Posts
    8

    response

    thanks for your post. Actually, I fieldName is the name of the column, I am referencing by that and I want the user to see the values in that column when they click on the comboBox but it is not populating.

  4. #4
    Join Date
    Feb 2007
    Location
    Gujranwala
    Posts
    104
    Okay. I think I understand what you require.

    In terms of functionality and features ASP.Net is quite differnet then ASP.

    You would need to use Javascript OR have to refereh the window on selection of value in combo box and then get that value in QueryString and display it in select box.

    Hope this helps..

    Thank you,
    Zeeshan Ahmed
    CEO
    itHighway

  5. #5
    Join Date
    Jan 2007
    Posts
    8

    more feedback

    thanks for your post, but this I dont think that's the issue: the problem is that when the user first sees the page there should be data bound to the combo box from the recordset and this is not happening.

    The Javascript should work when the user actually selects a value but i cant even get that far, meaning I cannot get to the point where there are values to select:

    When the user clicks on the combo box all he sees is blank space, nothing, no values, i need to bind the columns in the recordset to the combobox and i need to know if my syntax that i first posted is incorrect. thanks.

  6. #6
    Join Date
    Dec 2005
    Location
    Blackpool, UK
    Posts
    172
    Quote Originally Posted by MyronCope
    <CODE>
    <SELECT NAME="FieldD">
    <%

    While not rsRecordSet.EOF
    %>
    <OPTION VALUE="<%=rsRecordSet("FieldID")%>"></OPTION>
    <%
    rsRecordSet.MoveNext
    Wend
    If rsRecordSet.State = adStateOpen Then rsRecordSet.Close
    Set rsRecordSet= nothing
    %>
    </SELECT>
    </CODE>
    Thanks!!
    Do you mean the user cannot see the options within the combo box?

    Try
    <OPTION VALUE="<%=rsRecordSet("FieldID")%>"><%=rsRecordSet("FieldID")%></OPTION>

    this way the data is bound to the Option value and also displayed for the user.
    "To steal ideas from one person is plagiarism; to steal from many is research."

  7. #7
    Join Date
    Jun 2005
    Location
    Winston-Salem, NC
    Posts
    318
    If I understand what you want then you want the user to see Column names and not the actual data stored in the table. If so then try this code.
    Code:
    <option value="NA"></option>
    
    <%
       For iLoop = 0 to rsRecordSet.Fields.Count - 1 
    %>
    
    <option value="<% Response.Write rsRecordSet.Fields(iLoop).Name %>"><% Response.Write rsRecordSet.Fields(iLoop).Name %></option>
    
    <%
       Next
    %>
    
    </select>

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles