Wrox Programmer Forums
|
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 5th, 2007, 06:30 AM
Authorized User
 
Join Date: Jun 2006
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to sort data in a data grid?

After fetching data from an sql server, i'm splitting some data and showing to the user in a data grid.
for example, splitting the date time and display date, time in seperate columns.

I want to sort these two display field in either ascending or descending order. How do i do this?

Intellectuals solve problems but Genoius avoid problems.
__________________
Intellectuals solve problems but Genious avoid problems.
 
Old April 9th, 2007, 09:14 PM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 599
Thanks: 6
Thanked 3 Times in 3 Posts
Default

Couldn't you do that in your SQL statement ORDER BY?

 
Old April 10th, 2007, 02:09 AM
Authorized User
 
Join Date: Jun 2006
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Default

When i split datetime field into date time, how can i sort them using order by ,
coz sql does not have seperate date and time data types.

Intellectuals solve problems but Genoius avoid problems.
 
Old April 10th, 2007, 02:37 PM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 599
Thanks: 6
Thanked 3 Times in 3 Posts
Default

You could use this in your ORDER BY statement:

ORDER BY CONVERT(varchar(10), [Date Column], 101), CONVERT(varchar(5), [Date Column], 114)

The thing is, even if you split the data it still should ORDER BY in the same order as your SQL statement is ordering the date column. And this should work just as easily unless you wanted the date to order ascending and the time be descending then you would use the example above.

ORDER BY [Date Column] 'ASC or DESC

This will order by year ascending and time descending.

ORDER BY DATEPART(yy, InvDate) ASC, CONVERT(varchar(5), InvDate, 114) Desc

Richard








Similar Threads
Thread Thread Starter Forum Replies Last Post
How to sort a column in data grid: kenn_rosie ASP.NET 1.0 and 1.1 Basics 1 January 26th, 2006 02:03 PM
Export data from data grid to excel pomoc VB.NET 2002/2003 Basics 0 December 16th, 2005 03:11 PM
Export data from data grid to Excel pomoc Visual Basic 2005 Basics 0 December 16th, 2005 02:56 PM
trying to load db data into data grid itsajourney Beginning VB 6 2 June 7th, 2005 12:05 PM
sort data flyfish Access 5 February 7th, 2005 02:51 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.