Click here to Skip to main content
15,885,365 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Dear FRIENDS,

am working on ASp.NET, C#, SQLSERVER2005.

I have a GRIDVIEW on my Webpage and a dropdownlist. I have a column in that GRidview as Date Valid From

I used to SORT the DATES in Ascending Order from 2011 - 2012

My columns is as displays

DateValidFrom
===============================

01\01\2011
01\01\2011
01\02\2011
03\02\2011
03\04\2012 -
05\04\2012 -
03\03\2011
01\02\2011
03\02\2011
03\04\2012 -
05\04\2012 -
03\03\2011
04\04\2011


I need to arrange it in Ascending order. it should display from 2011 - 2012. when date validfrom ITEM Selected from dropdownlist.

Please help.
Posted
Comments
dimpledevani 6-Aug-12 4:06am    
If you are using datatable as a datasource to your gridview then use the dataview's sort method and try it

You can sort your date by using query itself..try simple sql query.
[updated]
SQL
select * from [table name] order by convert(nvarchar,DateValidFrom,103) 


Thanks
Ashish
 
Share this answer
 
v2
Comments
Ubaid ur Rahman IT 6-Aug-12 4:31am    
what is datefrom here
Ubaid ur Rahman IT 6-Aug-12 4:31am    
is it column name ?
AshishChaudha 6-Aug-12 4:33am    
its your column name..I have updated
Ubaid ur Rahman IT 6-Aug-12 4:53am    
This is my query

SqlDataAdapter dad3 = new SqlDataAdapter("select ClearanceNumber, CodeFlightId, DateLastChange, DateValidFrom,"
+ "DateValidTo, ReservationNo, AircraftType, CityCode, Days from Flight order by DateValidFrom", con);

Please help
AshishChaudha 6-Aug-12 4:54am    
SqlDataAdapter dad3 = new SqlDataAdapter("select ClearanceNumber, CodeFlightId, DateLastChange, DateValidFrom," + "DateValidTo, ReservationNo, AircraftType, CityCode, Days from Flight order by convert(nvarchar,DateValidFrom,103)", con);
why don't you get sorted data from database ?

add
SQL
order by date
to your select query
 
Share this answer
 
v2
Comments
Ubaid ur Rahman IT 6-Aug-12 4:26am    
already i have use dataviews sort method.........but its not sorting
Sangramsingh Pawar 6-Aug-12 4:37am    
use this in your database query it will work.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900