Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.0 and 1.1 Basics
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old April 5th, 2007, 06:30 AM
Authorized User
 
Join Date: Jun 2006
Location: Hyderabad, Andhrapradesh, India.
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.
  #2 (permalink)  
Old April 9th, 2007, 09:14 PM
Friend of Wrox
Points: 2,101, Level: 18
Points: 2,101, Level: 18 Points: 2,101, Level: 18 Points: 2,101, Level: 18
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2003
Location: , , .
Posts: 599
Thanks: 6
Thanked 3 Times in 3 Posts
Default

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

  #3 (permalink)  
Old April 10th, 2007, 02:09 AM
Authorized User
 
Join Date: Jun 2006
Location: Hyderabad, Andhrapradesh, India.
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.
  #4 (permalink)  
Old April 10th, 2007, 02:37 PM
Friend of Wrox
Points: 2,101, Level: 18
Points: 2,101, Level: 18 Points: 2,101, Level: 18 Points: 2,101, Level: 18
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2003
Location: , , .
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



 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 01:27 PM.


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