Hi all
I would like to know how can I sort my recordset by simply clicking on the table header.
I'm populating a table from recordset1 and would like to give the user the ability to sort it on the fly. Thanks in advance. Tony
you can do this by simply creating a form inside the table with the first row of the table as checkboxes, each check box can have a diferent value.
then the visitor clicks on submit or sort, whichever you call it, and you can have a simple script like
<%
dim choice
choice = request.form("chosen"
if choice = "1" then variable = "autonumber"
if choice = "2" then variable = "accountnumber"
etc etc
if choice = "" then variable = "autonumber"
%>
then on your query use
<%
query = "SELECT * FROM table SORT BY " & variable & " DESC"
%>
this will then depending on what is selected from the first part, pull the records from the database in the order needed
Will need to store the current sort order in a session variable, too, since most sites that offer that functionality allow it to sort one way by clicking once, and then the other by clicking again.
Compare to see if
(a) user clicked the same thing
(b) what current sort order is, and flip it if it is the same
or you can make each header a link to the same page with the sort fields in the querystring:
<%
Dim sortOrder
Dim sortField
Dim sSQL
sortField=Request.QueryString("s"
If sortField = "" Then
sortField = "Name" 'default to sort by name
End If
sortOrder=Request.QueryString("o"
If sortOrder = "" Then
sortOrder = "ASC" ' default to ascending
End If
sSQL = "SELECT * FROM tablename WHERE field='whatever' ORDER BY " & sortField & " " & sortOrder
..... continue db processing.....
'swap sort order
If sortOrder = "ASC" Then
sortOrder = "DESC"
Else
sortOrder = "ASC"
End If
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.