ASP Code
  Home arrow ASP Code arrow Small API Tag helper for Select and OPTION...
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
ASP CODE

Small API Tag helper for Select and OPTION tags
By: aspfree
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating:  stars stars stars stars stars / 0
    2000-03-26

    Table of Contents:

    Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


     

    Small API tag helper for SELECT and OPTION tags by Salim N.

    Attached is a small API that is a great helper for ASP programmers. It's a SELECT tag helper and contains advanced features such as Multiple OPTION caption for the Same OPTION value. It's not the most advance script routine in the world but it sure is helpful and a clean way to program.

    Here is the code

    <%
    '------------------------------------------------------------------------------
    'This is a generic <SELECT> Element Helper function
    '------------------------------------------------------------------------------
    'Written By: Salim Naim 20/3/2000
    'Note: I'm more than happy to fix any Bugs or answer any questions regarding the
    'sample,i can be reached at snaim@zfp.com or salimn@yahoo.com

    '------------------------------------------------------------------------------
    'Example Use 1:   
    'Simple basic usage
    'Call OutputSelect("country","COUNTRYNAME","COUNTRYNUM","","SELECT * FROM COUNTRIES","DSN=..")
    '------------------------------------------------------------------------------
    'Example Use 2:   
    'This will output multiple option captions for the <OPTION> selection
    'Call OutputSelect("USERS","FIRSTNAME,LASTNAMSE","USERNUM","","SELECT * FROM USERS","DSN=..")
    'Note: the field captions, must be delimited by a coma ,
    '------------------------------------------------------------------------------
    '######    USE THE szSelected PARAMETER TO SET A DEFAULT SELECTED OPTION #######
    '------------------------------------------------------------------------------

    '---------------------------------------------------------------------------------------
    ' Function:        OutputSelect
    ' Description:    This Functin is a Helper function that outputs
    '                 a <select>..</select> based on your query.
    '---------------------------------------------------------------------------------------
    ' Parameters:    name             -     This is the HTML ATTRIBUTE for NAME                
    '                 fiedlcaption     -    These are the Fieldsnames from the Database that
    '                                     you want to output in the <option>.
    '                                     {Note: can contain multiple, use [,] as a delimeter.)   
    '                 fieldvalue         -    This is the Database fieldname that you want to be as
    '                                     the VALUE ATTRIBUTE.   
    '                 szSelected         -    The SELECTED VALUE from the List.
    '                 szQry             -    The SQL Statment to populate the LIST from
    '                 szDSN             -    The Data Source Name for the RecordSet   
    '---------------------------------------------------------------------------------------
    Sub OutputSelect(name,fieldcaption,fieldvalue,szSelected,szQry,szDSN)
    Dim objRS
    Dim aCaptions,szCaption
    Dim i

    'first split all the captions into an array.
    aCaptions = split(fieldcaption,",")

    'create our recordset.
    Set objRS = Server.CreateObject("ADODB.RecordSet")
    if Not IsObject(objRS) then
    Response.Write "Out of Resources"
    Response.End
    End if

    'execute the Query
    objRS.Open szQry,szDSN
    if Not objRS.EOF then%>
    <%'start the list, output the NAME%>   
    <select name="<%=name%>">
        <option value=""></option>
    <%While Not objRS.EOF%>        
        <%'only output the values that are not selected
        if Not szSelected = objRS(fieldvalue) then%>
            <%'in the case that the value is empty output the caption as the value
            if Len(Trim(fieldvalue)) > 0 then%>
                <option value="<%=objRS(fieldvalue)%>">
                <%'Output every caption that is in the array
                for each szCaption in aCaptions%>
                    <%if Len(Trim(szCaption)) > 0 then%>
                    <%=objRS(szCaption)%>&nbsp;
                    <%end if%>
                <%next%>
                </option>
            <%else%>
                <option value="<%=objRS(fieldcaption)%>">
                <%for each szCaption in aCaptions%>                
                    <%if Len(Trim(szCaption)) > 0 then%>
                    <%=objRS(szCaption)%>&nbsp;
                    <%end if%>                
                <%next%>    
                </option>
            <%end if%>
        <%'the selecte values
        else%>
            <option value="<%=objRS(fieldvalue)%>" selected>
            <%for each szCaption in aCaptions%>            
                <%if Len(Trim(szCaption)) > 0 then%>
                <%=objRS(szCaption)%>&nbsp;
                <%end if%>            
            <%next%>   
            </option>
        <%end if%>       
        <%objRS.MoveNext   
    Wend%>
    </select>
    <%End if
    'close up everything
    Call objRS.Close()
    'free resources.
    Set objRS = Nothing
    End Sub%>

    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

    More ASP Code Articles
    More By aspfree

     

    IBM® developerWorks developerWorks - FREE Tools!


    NEW! Calling all CC Power Users – and those that would like to be!

    Join this Rational Talks to You teleconference, featuring Paul Boustany and Mark Krasovich, to speak to the experts about becoming a Rational ClearCase power user. Get a chance to ask your questions and learn tips and tricks for using Rational ClearCase in Agile development
    FREE! Go There Now!


    NEW! Addressing software-as-a-service challenges using Tivoli security and WebSphere solutions

    Building a software-as-a-service solution requires addressing a few key technical challenges. In this webcast, we'll focus on the role of IBM Tivoli Directory Server and WebSphere Portlet Factory in creating a Software as a Service solution. We will demonstrate how to use Tivoli Directory Server to prevent the user population of one tenant from accessing the virtual portal and portlet components of another tenant. We will also use the dynamic profile capability of WebSphere Portlet Factory to create multiple highly customized applications from one code base.
    FREE! Go There Now!


    NEW! Application Development Tools for the Mainframe Developer

    You probably have thousands of lines of COBOL code loaded with business intelligence and being used to run your business, along with an army of developers maintaining these applications. Learn how to prepare your applications and developers so you can keep that competitive edge and move to a service-oriented architecture with the IBM Rational Enterprise Modernization solutions. Replay is available for 9 months.
    FREE! Go There Now!


    NEW! Download IBM Rational Developer for System z

    Download a free trial version of IBM Rational Developer for System z, software that can help you deliver core development capabilities; the power of Java Platform, Enterprise Edition (Java EE); and rapid application development support to diverse enterprise application development teams. With comprehensive development tools to help create, deploy and maintain traditional enterprise and composite applications, Rational Developer for System z enables developers with different technical backgrounds to easily participate in important technology projects.
    FREE! Go There Now!


    NEW! Hello World: Monitor a simple business process using WebSphere Business Monitor V6.0.2

    This tutorial shows new users of IBM WebSphere Business Monitor Version 6.0.2 how to perform the "Hello World" equivalent for monitoring business process applications. It is intended to help you get familiar with the capabilities of the product.
    FREE! Go There Now!


    NEW! Innovate don't duplicate! Asset reuse strategies for success

    Asset Reuse is a key strategy for companies looking to create innovative solutions to solve complex software development problems. Searching for, identifying, updating, using and deploying software assets can be a difficult challenge. Listen to this webcast, to learn about strategies and tools that you can leverage for a successful project, including Rational Asset Manager, Rational Software Architect and WebSphere Service Registry and Repository.
    FREE! Go There Now!


    NEW! Integrating XML into Your Enterprise Using Data Federation

    XML has become a common way of storing business data as flat files and many data server vendors including IBM have provided ways to store this data within relational database systems. Increasingly collections of XML files are accessed like databases using an xQuery and other XML standard mechanisms. Businesses find the need to combine the traditional tabular structured data with XML formatted data. In this webcast, you’ll learn about IBM’s WebSphere Federation Server technology, which provides users with the ability to integrate these two data formats.
    FREE! Go There Now!


    NEW! Using Rational Business Developer to enhance your developer productivity

    Join this Rational Talks to You teleconference, to hear how Enterprise Generation Language (EGL) eliminates the need for tedious and error-prone low level coding, so developers can focus on business requirements. EGL extends the Rational software development platform with a simplified programming language that enables developers who have little or no experience with Java, Web technologies or Service Oriented Architecture, to create enterprise-class applications and services quickly and easily. It also allows developers who may have little or no mainframe programming experience to quickly create traditional mainframe components.
    FREE! Go There Now!


    NEW! Webcast: What is new in Viper 2 for developers?

    Viper 2 brings a great value to developer communities including SQL, XML, PHP, Ruby, .NET and Java. You probably already know that DB2 Express-C is free for developers to develop, deploy and distribute. Viper 2 provides a variety of means that help move your application from the development stage to deployment more rapidly. This webcast shows how to best utilize the latest tools available for developing DB2 applications.
    FREE! Go There Now!


    Refresh! IBM Rational Systems Development Solution eKit

    With IBM Rational Systems Development Solution, you can deliver products faster with higher quality. Within this kit, Read the “Model Driven Systems Development” white paper to see how to improve product quality and communication. Then check out the rest of the e-Kit to learn more about important topics that can affect the success of any software project through customer examples, tutorials, informative Webcasts, and best practices for designing, building and managing systems. From start to finish, at every stage in your projects, Rational Systems Development Solution can help your company reach its full potential.
    FREE! Go There Now!



    All FREE IBM® developerWorks Tools!

    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...
    - Various methods of setting Date values to a ...
    - Conditional DataGrid Item and using checkbox...
    - Fill .NET Listbox with SQL DataReader
    - Filling Dropdown box using Code-Behinds in C#
    - FLAMES code sample written in .NET What is F...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek