473,386 Members | 1,823 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

ASP Sorting Problem

Hi all,

I wanna ask how to do the following sorting function,
for example

Name Age
Brian 22
Alice 17
Patrick 21

when click on name, it will sort by
Alice
Brain
Patrick

when click on age, it will sort by
17
21
22

Is it execute the SQL by hyperlink..?
Can anyone give me an example?
Any help will be greatly appreciate..


Jul 19 '05 #1
2 2712
Create links like:

<a href="results.asp?sortBy=Name">name</a>
<a href="results.asp?sortBy=Age">age</a>

and then in your results.asp page you do something like:

<%
strSQL = _
"SELECT [Name], Age " & _
"FROM Users"

strSortBy = Request.QueryString("sortBy")

Select Case strSortBy
Case "Name"
strSQL = strSQL & " ORDER BY [Name]"
Case "Age"
strSQL = strSQL & " ORDER BY Age"
End Select

Response.Write(strSQL)
%>

Cheers
Ken
"Henry Wiz" <co*****@cocoman.net> wrote in message
news:c3*********@imsp212.netvigator.com...
: Hi all,
:
: I wanna ask how to do the following sorting function,
: for example
:
: Name Age
: Brian 22
: Alice 17
: Patrick 21
:
: when click on name, it will sort by
: Alice
: Brain
: Patrick
:
: when click on age, it will sort by
: 17
: 21
: 22
:
: Is it execute the SQL by hyperlink..?
: Can anyone give me an example?
: Any help will be greatly appreciate..
:
:
:
:
Jul 19 '05 #2
"Henry Wiz" wrote:

I wanna ask how to do the following sorting function,
for example

Name Age
Brian 22
Alice 17
Patrick 21

when click on name, it will sort by
Alice
Brain
Patrick

when click on age, it will sort by
17
21
22


You can either let SQL sort for you or sort it yourself in ASP. Based on
your subject line, I'll show you one way to do it in ASP. My example is in
JScript.

Assuming you have executed a SQL query and received a recordset RS, you can
proceed as follows:

var People = new Array(),
SortBy = Request.QueryString("SortBy").Item/1 || 0
while (!RS.EOF) {
People.push([RS.Fields("Name").Value,RS.Fields("Age").Value])
RS.MoveNext()
}
People.sort(function(a,b){return a[SortBy]<b[SortBy]?1:-1})

At this point, the array [People] is sorted. Your corresponding column
headers would look something like this:

<TD><A HREF="MyScript.asp">Name</A></TD>
<TD><A HREF="MyScript.asp?SortBy=1">Age</A></TD>

You can throw a multiplier into the sort function if you want to add the
ability to sort in reverse.
--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms. Please do not contact
me directly or ask me to contact you directly for assistance. If your
question is worth asking, it's worth posting.
Jul 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: dont bother | last post by:
This is really driving me crazy. I have a dictionary feature_vectors{}. I try to sort its keys using #apply sorting on feature_vectors sorted_feature_vector=feature_vectors.keys()...
9
by: jwedel_stolo | last post by:
Hi I'm creating a dataview "on the fly" in order to sort some data prior to writing out the information to a MS SQL table I have used two methods in order to determine the sort order of the...
7
by: Federico G. Babelis | last post by:
Hi All: I have this line of code, but the syntax check in VB.NET 2003 and also in VB.NET 2005 Beta 2 shows as unknown: Dim local4 As Byte Fixed(local4 = AddressOf dest(offset)) ...
4
by: John Bullock | last post by:
Hello, I am at wit's end with an array sorting problem. I have a simple table-sorting function which must, at times, sort on columns that include entries with nothing but a space (@nbsp;). I...
4
by: FBM | last post by:
Hi, I am working on a program that simulates one of the elements of ATM. The simulation stores events which occurs every some milliseconds for a certain amount of time. Every time that an event...
4
by: Ambica Jain | last post by:
Hi, I want custom sorting on some of the columns in the datagrid. And i am able to do the same by overriding MouseDown event. However, i need to rebind my datatable to reflect the changes in...
7
by: Kamal | last post by:
Hello all, I have a very simple html table with collapsible rows and sorting capabilities. The collapsible row is hidden with css rule (display:none). When one clicks in the left of the...
1
by: Ahmed Yasser | last post by:
Hi all, i have a problem with the datagridview sorting, the problem is a bit complicated so i hope i can describe in the following steps: 1. i have a datagridview with two columns...
1
KevinADC
by: KevinADC | last post by:
Introduction In part one we discussed the default sort function. In part two we will discuss more advanced techniques you can use to sort data. Some of the techniques might introduce unfamiliar...
7
Plater
by: Plater | last post by:
I am having trouble determining when my DataGridView object is sorting (based on a column header click). The idea is, in a large table, sorting the columns takes time, so I show a splash screen....
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.