Dynamically sort records using Drop Down/ASP

Posted on 2005-05-09
Last Modified: 2010-04-17
Dear Friends,

Hello. I have a small script that loops to display records in columns on my web page. I need to add a feature that will give the users an option to sort by 'open' or'closed' status, say for instance a drop down field...where you can choose open or closed and click a button then it will show only records by the option you chose in the drop down (OPEN OR CLOSED RECORDS)

  set rs=Server.CreateObject("adodb.Recordset")
   Set adoCon = Server.CreateObject("ADODB.Connection")
adoCon.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("/database.mdb")

  sqlstmt = "SELECT ID,Name,Number,Product from Users" ( I WILL ADD STATUS HERE) sqlstmt, adoCon
  If rs.eof then
      response.write "<center>There are no records in the database"
        response.write "<br>Please check back later</center>"

html to display records in columns with headers... ('I'll ADD A DROP DOWN ABOVE so users can choose to display open or closed status records...)

  End If

Question by:butter_fly
    LVL 12

    Accepted Solution

    >  sqlstmt = "SELECT ID,Name,Number,Product from Users" ( I WILL ADD STATUS HERE)
    > sqlstmt, adoCon

    Not exactly sure what you are asking but is this close to what you are looking for?

    sqlstmt = "SELECT ID,Name,Number,Product from Users where yourOpen\Closed field = "" & dropDown.value & "'"


    Author Comment

    yes, something along those lines..

    My current code has a hardcoded select statement, I want to make it dynamic so that the user can pick which records they want displayed (only open or only closed).   The code currently loops to display all records which are both open and closed records.

    Is it possible to have a drop down menu for the user to select open or closed records? I hope I make sense.

    ...thanks for your reply =)

    Author Comment

    I figured out a work around, but I'd like to give you the points Bob cuz you are the only person that answered. =)

    Have a wonderful Day
    LVL 12

    Expert Comment

    Thanks butter_fly. I think maybe I could have explained better.
    In the select statement......
    sqlstmt = "SELECT ID,Name,Number,Product from Users where yourOpen\Closed field = "" & dropDown.value & "'"
         The dropDown.value is a variable that can be dynamically filled. Your dropdown list from which the user makes a selection, will have a value that you can put into this variable before executing the sql statement.
    Does that help clarify any?

    Featured Post

    Gigs: Get Your Project Delivered by an Expert

    Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

    Join & Write a Comment

    Suggested Solutions

    Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
    Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
    In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
    In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    24 Experts available now in Live!

    Get 1:1 Help Now