Bullschmidt.com
Home
Web Database Concept
How We Work Together
Bio
Web Database Sample
Classic ASP Design Tips
Bar Chart Tool
Web Design Resources
Access Database Sample
Classic ASP Design Tips
Listbox for Sorting
These are opinions of J. Paul Schmidt, MBA.
No warranties are either expressed or implied.
To Use Paul's Services:
Paul@Bullschmidt.com
You might wish to have a listbox that allows the user to sort the records shown on the page by things like the Name, City, or Zip.
First note that the form is set to submit to itself:
<form id="frmMain" name="frmMain" action="<%= Request.ServerVariables("SCRIPT_NAME") %>" method="post">
And note that the Sort listbox's onchange event triggers a form submit:
Sort By
<select name="Sort" size="1" onchange="document.frmMain.submit();">
<option value="">
<option value="Name">Name
<option value="City">City
<option value="Zip">Zip
</select>
Toward the top of the VBScript code on the page set a variable called Sort:
' If there was a post, get the Sort, otherwise the Sort should be Name.
If Request.TotalBytes > 0 Then ' Or this could be If Request.Form("Sort") <> "" Then
Sort = Request.Form("Sort")
Else
Sort = "Name"
End If
And the SQL statement's ORDER BY clause would be based on the posted form value of the Sort listbox. And note that secondary sorts are also used so that if the sort is to be the city that those within the same city are sorted by name:
strSQL = "SELECT * FROM MyTable "
If Sort = "Name" Then
strSQL = strSQL & "ORDER BY LName, FName"
Elseif Sort = "City" Then
strSQL = strSQL & "ORDER BY City, LName, FName"
Elseif Sort = "Zip" Then
strSQL = strSQL & "ORDER BY Zip, LName, FName"
End If
To Use Paul's Services:
Paul@Bullschmidt.com
Copyright © 2000-2010
J. Paul Schmidt, MBA
Freelance Web and Database Developer
All Rights Reserved
Privacy Policy