0

Simple gridview. SqlData source to bind data to gridview. A column called Date ( type date ) where I add the date when I edited something.

I would like to sort the entire gridview columns by the date column.

Any idea how can I do that?

THanks

Inaa Inzii
  • 121
  • 1
  • 4
  • 14

2 Answers2

0
  1. As this is a Page level problem. So you can first keep the GridView DataSource in ViewState
  2. Keep a hyperlink like control in your header and during Postback retrieve the data from ViewState. Sort it according to the required parameter . Bind it again to the GridView.

Example here and here

Community
  • 1
  • 1
Pankaj
  • 9,749
  • 32
  • 139
  • 283
  • Yea..the problem is that I'm not so advanced in asp.net , if you don't mind showing me some samples or something – Inaa Inzii Apr 11 '12 at 08:35
0

An easy way to do this is add an additional column to your SQL select statement. This extra column will be the edit date in a format that can be used for sorting (YYYYMMDD format):

CONVERT(VARCHAR(8), [Date], 112) as sortedDate

Then change your edit date field to use your sorted date field as the sort expression:

<asp:BoundField DataField="Date" HeaderText="Edit Date" SortExpression="sortedDate"/>
sgun
  • 11
  • 1