If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ASP > inserting hyperlinks to sort data

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-09-05, 11:01
bla4free bla4free is offline
Registered User
 
Join Date: Jan 2005
Posts: 165
inserting hyperlinks to sort data

I have an asp page which displays the results of a query. is there a way to insert hyperlinks above the data so when clicked, it will sort the data ascending/descending...something like that. here's an example. i have my table. at the top of the table i have the column names. i want to hyperlink the column names so when clicked, it will sort the data based on that column. thanks for any help.
Reply With Quote
  #2 (permalink)  
Old 03-09-05, 17:12
rokslide rokslide is offline
Registered User
 
Join Date: Nov 2003
Location: Christchurch, New Zealand
Posts: 1,617
If you want to sort you need to re-run the query that collected the data and add and orber by clause.... eg
Code:
select * from cases order by caseNumber
(of course don't use * specify your fields)

So you make the order by part of your sql statement dynamic and pass the field you want to order by in the querystring... something like...
Code:
<a href="caseResults.asp?orderby=caseNumber">Case Number</a>
and
Code:
strSql = "select * from cases"
orderBy = Request.QueryString("orderby")
if orderBy<>"" then strSql = strSql + "order by " orderBy
if you have a where clause included in the query you will need to make sure you have access to the data for this where clause as well.
Reply With Quote
  #3 (permalink)  
Old 03-09-05, 21:59
Bullschmidt Bullschmidt is offline
Guru
 
Join Date: Jun 2003
Location: USA
Posts: 1,032
And here's a related resource:

Database Sort
http://www.asp101.com/samples/db_sort.asp
__________________
J. Paul Schmidt, Freelance Web and Database Developer
www.Bullschmidt.com
Access Database Sample, Web Database Sample, ASP Design Tips
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On