473,473 Members | 2,104 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Sorting a form asc/desc

3 New Member
Expand|Select|Wrap|Line Numbers
  1. <HTML>
  2. <head>
  3. <title>Migration Admin Page</title>
  4. <META NAME="Generator" CONTENT="EditPlus">
  5. <META NAME="Author" CONTENT="NICHOLAS JONES">
  6. <link  type="text/css" rel="stylesheet" href="StyleSheets/page_style1.css">
  7. <link type="text/css" rel="stylesheet" href="StyleSheets/Titan1.css">
  8. </head>
  9. <BODY>
  10.  
  11. <%
  12. Dim strConnString  
  13. Dim objConn        
  14. Dim objRS           
  15. Dim strSqlQuery    
  16. Dim strSortField   
  17. Dim strSortOrder  
  18. Dim objField      
  19. Dim blnColor      
  20.  
  21. strConnString = "DRIVER=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX;" _
  22.     & "Connect Timeout=15;"
  23.  
  24. strSortField = Request.QueryString("field")
  25. Select Case LCase(strSortField)
  26.     Case "name", "emailadd", "login", "deptname", "compname", "readymigrate", "comment", "datesubmitted"
  27.         strSortField = strSortField
  28.     Case Else
  29.         strSortField = "record_id"
  30. End Select
  31.  
  32. ' Check for descending o/w default to ascending
  33. Select Case LCase(Request.QueryString("order"))
  34.     Case "desc"
  35.         strSortOrder  = "desc"
  36.     Case Else
  37.         strSortOrder  = "asc"
  38. End Select
  39.  
  40. strSqlQuery = "SELECT * FROM [sample] ORDER BY [" & strSortField & "] " & strSortOrder & ";"
  41.  
  42. Set objConn = Server.CreateObject("ADODB.Connection")
  43. objConn.Open strConnString
  44.  
  45. Set objRS = Server.CreateObject("ADODB.Recordset")
  46. objRS.Open "migrate", objConn
  47.  
  48. Response.Write "<table border=""1"" cellspacing=""0"">" & vbCrLf
  49.  
  50. ' Write titles and include links to sort the table by each field
  51. Response.Write vbTab & "<tr>" & vbCrLf
  52. For Each objField in objRS.Fields
  53.     Response.Write vbTab & vbTab & "<td  bgcolor=""#CCCCCC""><strong>" & objField.Name
  54.     %><br>
  55.     <%
  56.     Response.Write "("
  57.     Response.Write "<a href=""? & field=" & objField.Name & "&order=asc"">+</a>"
  58.     Response.Write " / "
  59.     Response.Write "<a href=""? & field=" & objField.Name & "&order=desc"">-</a>"
  60.     Response.Write ")</strong></td>" & vbCrLf
  61.  
  62.     Response.Write "</td>" & vbCrLf
  63. Next 'objField
  64. Response.Write vbTab & "</tr>" & vbCrLf
  65.  
  66.  
  67.  
  68. ' Display the data
  69. blnColor = False
  70. objRS.MoveFirst
  71. Do While Not objRS.EOF
  72.     'Response.Write objRS.Fields(0).Value & "<br />" & vbCrLf
  73.  
  74.     Response.Write vbTab & "<tr>" & vbCrLf
  75.     For Each objField in objRS.Fields
  76.         Response.Write vbTab & vbTab & "<td bgcolor="""
  77.  
  78.         ' Decide what color to output
  79.         If blnColor Then
  80.             Response.Write "#CCCCFF"  ' Light blueish
  81.         Else
  82.             Response.Write "#FFFFFF"  ' White
  83.         End If
  84.  
  85.         Response.Write """>" & Trim(objField.Value) & "</td>" & vbCrLf
  86.     Next 'objField
  87.     Response.Write vbTab & "</tr>" & vbCrLf
  88.  
  89.     blnColor = Not blnColor
  90.  
  91.     objRS.MoveNext
  92. Loop
  93.  
  94. Response.Write "</table>" & vbCrLf
  95.  
  96. objRS.Close
  97. Set objRS = Nothing
  98. objConn.Close
  99. Set objConn = Nothing
  100. %>
  101. </BODY>
  102. </HTML>
I've run a quick search and tried loads of methods but I cannot for the life of me make the (+/-) sort function work with this piece of script.

The URL changes indicating it is either running in ascending order for the selected field or descending order but nothing happens.

Any help will be much appreciated. Thanks
Nov 13 '07 #1
1 2368
jhardman
3,406 Recognized Expert Specialist
Nick,

I don't know what "migrate" means in this context, line 46 should be something like this:
Expand|Select|Wrap|Line Numbers
  1. objRS.Open strSQLQuery, objConn
Let me know if this helps.

Jared
Nov 17 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

12
by: pmud | last post by:
Hi, I am using teh following code for sorting the data grid but it doesnt work. I have set the auto generate columns to false. & set the sort expression for each field as the anme of that...
2
by: Aravind | last post by:
Hi folks. I have a form, frmHistory, which has 4 command buttons: Sort Title (cmdSortTitle), Sort Name (cmdSortName), Due Today (cmdDueToday), and Due List (cmdDueList). Sort Title and Sort...
2
by: Mike P | last post by:
I have just written my first page with a datagrid that allows ASC and DESC sorting. But I want to know how I can get it so that the header shows the type of sorting that has just been done on it...
1
by: Jeremy | last post by:
I want my gird to sort only the items on the current page when I click on a column header. I wrote a little test app, but when I sort it pulls in items from other pages and places them on the current...
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...
0
by: rupalirane07 | last post by:
Both grids displays fine. But the problem is only parent datagrid sorting works fine but when i clik on child datagrid for sorting it gives me error: NullReferenceException error Any...
6
by: =?Utf-8?B?RGFu?= | last post by:
I am reposting a question from about 3 weeks ago ("sorting capability"). I have an aspx page in which I get the data from a database dynamically, through C# code, by creating a dynamic table...
3
by: nagmvs | last post by:
Hi to all I have one table with 6 columns and 20 rows.I want to sort each and every column when i click the column name in the table. for sorting i create one more page.when i click the column...
2
by: ARC | last post by:
I have a ranking report where I want to sort it different ways depending on the option the user picks. On the On_Open event, I've tried everything I can think of and keep getting error 3071 "This...
5
by: jrod11 | last post by:
hi, I found a jquery html table sorting code i have implemented. I am trying to figure out how to edit how many colums there are, but every time i remove code that I think controls how many colums...
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.