ASP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingASP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old July 2nd, 2009, 09:58 PM
suprapen suprapen is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jul 2009
Posts: 4 suprapen User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 37 m 28 sec
Reputation Power: 0
Dynamic sorting header

I am trying to incorporate dynamic header with reverse sorting from this ASP 101 example sort script:
Code:
<!-- #include file="adovbs.inc" -->
<%
' ADO constants included above.  Questions about adovbs.inc?
' See "What is Adovbs.inc and Why Do I Need It?"
'   (URL address blocked: See forum rules)

Dim strConnString  ' SQL Server connection string
Dim cnnDbSort      ' ADO Connection object
Dim rstDbSort      ' ADO Recordset object
Dim strSqlQuery    ' Our SQL query
Dim strSortField   ' Field to sort by
Dim strSortOrder   ' "ASC" or "DESC"
Dim objField       ' Used for table display
Dim blnColor       ' Alternating color indicator

' Set our connection string
strConnString = "Provider=SQLOLEDB;Data Source=10.2.2.133;" _
	& "Initial Catalog=samples;User Id=samples;Password=password;" _
	& "Connect Timeout=15;Network Library=dbmssocn;"


' Retrieve sorting parameters:
' Get the field name and make sure the input is one of our field names.
strSortField = Request.QueryString("field")
Select Case LCase(strSortField)
	Case "last_name", "first_name", "sales"
		strSortField = strSortField
	Case Else
		strSortField = "id"
End Select

' Check for descending o/w we default to ascending
Select Case LCase(Request.QueryString("order"))
	Case "desc"
		strSortOrder  = "desc"
	Case Else
		strSortOrder  = "asc"
End Select

' Build our SQL query
strSqlQuery = "SELECT * FROM [sample] ORDER BY [" & strSortField & "] " & strSortOrder & ";"

' Open connection
Set cnnDbSort = Server.CreateObject("ADODB.Connection")
cnnDbSort.Open strConnString

' Get recordset
Set rstDbSort = Server.CreateObject("ADODB.Recordset")
rstDbSort.Open strSqlQuery, cnnDbSort

' Build our table:

' Start the table
Response.Write "<table border=""1"" cellspacing=""0"">" & vbCrLf

' Write titles and include links to sort the table by each field
Response.Write vbTab & "<tr>" & vbCrLf
For Each objField in rstDbSort.Fields
	Response.Write vbTab & vbTab & "<td bgcolor=""#CCCCCC""><strong>"
	If objField.Name = strSortField And strSortOrder = "asc" Then
		Response.Write "<a href=""?field=" & objField.Name & "&order=desc"">" & objField.Name & "</a>"
	Else
		Response.Write "<a href=""?field=" & objField.Name & "&order=asc"">" & objField.Name & "</a>"
	End If
	Response.Write "</strong>"

	If objField.Name = strSortField Then
		If LCase(strSortOrder) = "asc" Then
			Response.Write "&nbsp;<img src=""images/arr_up.gif"" width=""9"" height=""7"" border=""0"" alt=""Up Arrow"">"
			Response.Write "&nbsp;&uarr;&nbsp;"
		Else
			Response.Write "&nbsp;<img src=""images/arr_dn.gif"" width=""9"" height=""7"" border=""0"" alt=""Down Arrow"">"
			Response.Write "&nbsp;&darr;&nbsp;"
		End If
	End If

	Response.Write "</td>" & vbCrLf
Next 'objField
Response.Write vbTab & "</tr>" & vbCrLf



' Display the data
blnColor = False
rstDbSort.MoveFirst
Do While Not rstDbSort.EOF
	'Response.Write rstDbSort.Fields(0).Value & "<br />" & vbCrLf
	
	Response.Write vbTab & "<tr>" & vbCrLf
	For Each objField in rstDbSort.Fields
		Response.Write vbTab & vbTab & "<td bgcolor="""

		' Decide what color to output
		If blnColor Then
			Response.Write "#CCCCFF"  ' Light blueish
		Else
			Response.Write "#FFFFFF"  ' White
		End If

		Response.Write """>" & Trim(objField.Value) & "</td>" & vbCrLf
	Next 'objField
	Response.Write vbTab & "</tr>" & vbCrLf

	' Toggle our colors
	blnColor = Not blnColor

	rstDbSort.MoveNext
Loop

' End the table
Response.Write "</table>" & vbCrLf

' Close data access objects and free variables
rstDbSort.Close
Set rstDbSort = Nothing
cnnDbSort.Close
Set cnnDbSort = Nothing
%>

Anyone know how I can choose to not show some of the columns, right now it is returning all the fields in the sql select statement? example like id and sales but yet can select those fields in my sql query? Also instead of using the exact field name, can I replace those names with something more formatted? like Last Name for the last_name field. Help would be highly appreciated. Thank you!

id ↑ last_name first_name sales
1 Fuller Andrew 5000
2 Leverling Janet 6250
3 Buchanan Steven 3245
4 Peacock Margaret 4685
5 King Robert 5290
6 Andersen David 6420
7 Edwards Frank 3840
8 Richards Kate 4260
9 Jones Edward 3450
10 Callahan Laura 3675
11 Miller Greg 5640
12 Steel Tammy 3570
13 Dodsworth Nancy 2750
14 Nelson Beth 4345
15 Hopkins Peter 6710
16 Graham Chris 4050
17 Thompson Vincent 4820
18 Ostrander Ian 3965
19 Quinn Howard 5865
20 Smith Fred 6370
21 Ingraham Owen 4750
22 Youngs Quincy 4420
23 Zimmerman Walter 4980
24 Valentino Linda 2965
25 Underwood Debra 3790
26 Xavier Simon 5580
27 White Mark 4500

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingASP Development > Dynamic sorting header


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump





 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 4 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek