Using GetString Method to Populate a dropdown box by Michael Ryan

Contributed by
Rating: 4 stars4 stars4 stars4 stars4 stars / 5
October 22, 2000
Rate this Article:
MEH MEH++


SEARCH ASP FREE
TOOLS YOU CAN USE

advertisement

Using GetString Method to Populate a dropdown box by  Michael Ryan

This example is an extension of the Populating a dropdown box from a database.   Generally for select boxes, I use the .getstring method which I find tends to be faster usually than just looping.  Below is the code,


Original Code

Original Example as is just using Looping
<select size=1 onChange="gotohref(this);">
<option SELECTED>Navigate Our Site</option>
<% Do While Not rs.EOF %>
    <option value="<% = rs("id") %>"><% = rs("field1") %></option>
    <% rs.movenext %><% loop %>
</select>



Code for GetString Method

The original query must contain 2 (only) fields, 1st for value, 2nd for text may seem like more code, but the getstring will return the text faster than a loop I think the getstring method is also great for passing data to the client, for client-scripting using split method.

<%
dim sOptionText

If rs.BOF or rs.EOF Then
        sOptionText = "<option value='invalid'>No options available</option>"
Else
        sOptionText = "<OPTION VALUE='invalid' SELECTED>Navigate Our Site</OPTION>" _
        & vbCRLF & "<OPTION VALUE='" _
        & rsResults.GetString(2,,"'>","</OPTION>" & vbCRLF & "<OPTION
        VALUE='","")
End If
%>
<select size=1 onChange="gotohref(this);">
<%=Left(sOptionText,InStrRev(sOptionText,"<OPTION"))%>
</select>

blog comments powered by Disqus
ASP CODE ARTICLES

- ASP Forms
- ASP: The Beginning
- Getting Remote Files With ASP Continued
- Inbox and Outbox Manipulation in ASP
- Relational DropDownList Using VB.NET
- Ad Tracking URL Hits
- Use ViewState to display one record per page...
- Send Email using ASP.NET formatted in HTML
- ASP File Explorer
- ASP/XML Interview questions by Srivatsan Sri...
- Pressing RETURN won't submit the form
- This shows how you get the TEXT of a combo r...
- Group Data by Adrian Forbes
- Multiple checkbox select sample
- Multiple checkbox select with all values sam...

ASP Web Hosting ASP.Net Web Hosting Windows Web Hosting
 
 
 

ASP Free Forums 
 RSS  Tutorials RSS
 RSS  Forums RSS
 RSS  All Feeds
Site Map 
Request Media Kit
Write For Us Get Paid 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Privacy Policy 
Support 


© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 10 - Follow our Sitemap
Most Popular Topics
All ASP.Net Tutorials