Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET SQL-Server
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 5-Aug-12 23:03pm
Comments
dimpledevani at 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
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

You can sort your date by using query itself..try simple sql query.
[updated]
select * from [table name] order by convert(nvarchar,DateValidFrom,103) 
 
Thanks
Ashish
  Permalink  
v2
Comments
Ubaid ur Rahman IT at 6-Aug-12 4:31am
   
what is datefrom here
Ubaid ur Rahman IT at 6-Aug-12 4:31am
   
is it column name ?
AshishChaudha at 6-Aug-12 4:33am
   
its your column name..I have updated
Ubaid ur Rahman IT at 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 at 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);
Ubaid ur Rahman IT at 6-Aug-12 4:54am
   
how to write your query in my query ......please help.
Ubaid ur Rahman IT at 6-Aug-12 5:56am
   
My dear Friend, this is not sorting.........First it displays 2012 records and while paging on another pages 2011, 2012.....its not sorted....Please help
AshishChaudha at 6-Aug-12 6:08am
   
First clarify your question. Have you defined paging in your gridview????? According to you please tell me what sorting means????
Ubaid ur Rahman IT at 6-Aug-12 6:55am
   
yes, i have defined paging in my GRIDVIEW. I need dates in ascending order I have lot of 2011 and 2012 records in my GRIDVIEW.
 
also I have a dropdownlist above GRIDVIEW, when i select Datevalidfrom from dropdownlist.......... DATEVALIDFROM column must be Sorted
 

Please Please Please help.
 
Thanks in ADVANCE.
Ubaid ur Rahman IT at 6-Aug-12 6:59am
   
First Display 2011 records and then 2012 records.....see this, I need Exactly like this
 
01\01\2011
01\01\2011
02\01\2011
16\01\2011
26\01\2011
31\01\2011
02\01\2012 -
05\01\2012
06\01\2012
11\01\2012
15\01\2012
11\02\2012
AshishChaudha at 6-Aug-12 8:07am
   
SqlDataAdapter dad3 = new SqlDataAdapter("select ClearanceNumber, CodeFlightId, DateLastChange, DateValidFrom," + "DateValidTo, ReservationNo, AircraftType, CityCode, Days from Flight order by year(DrpDatevalidfrom.SelectedText.Trim())", con);
 
It will surely work..
AshishChaudha at 7-Aug-12 2:50am
   
Is this issue solved???
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

why don't you get sorted data from database ?
 
add
order by date
to your select query
  Permalink  
v2
Comments
Ubaid ur Rahman IT at 6-Aug-12 4:26am
   
already i have use dataviews sort method.........but its not sorting
Sangramsingh Pawar at 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)

  Print Answers RSS
0 OriginalGriff 7,903
1 Sergey Alexandrovich Kryukov 7,192
2 DamithSL 5,604
3 Manas Bhardwaj 4,986
4 Maciej Los 4,820


Advertise | Privacy | Mobile
Web01 | 2.8.1411023.1 | Last Updated 6 Aug 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100