Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do i sort the resultset 1

Status
Not open for further replies.

Natraj

IS-IT--Management
Jan 27, 2003
8
GB
Hi<br>
I am displaying the resultset on my browser, now i want to use a method by which, when the user click on the column heading the data is sorted on that column. Can anyone suggest a method to do this using VBScript.<br>
PS:Its urgent, need to complete a project.<br>
Natraj
 
The best way that I know of to do this is to use the ORDER BY clause in your SQL.

Try something like this....

<% 'build sql statement
strSQL = &quot;Select .... From .... Where ....&quot;

'check for a sort field in the Request.Querystring object
If Request.Querystring(&quot;sortby&quot;) <> &quot;&quot; then
strSQL = strSQL & &quot; Order by &quot; & _
Request.Querystring(&quot;sortby&quot;)
End If

'open you recordset as usual
%>

As you build your page, when it comes to creating the
column headers, place links in them to reload the page with
the correct sortby field passes as a parameter.

Ex: <a href=&quot;asppage.asp?sortby=<your field name>&quot;>Field Name</a>

If you are using buttons or whatever instead of links in a table, you could do that on the onclick event.

Now when the user clicks on the field, you will pass the sortby field to the page which will then use the ORDER BY to sort your recordset.

Hope that helps...Ron
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top