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
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
Page level
problem. So you can first keep the GridView DataSource
in ViewState
Postback
retrieve the data from ViewState
. Sort it according to the required parameter . Bind it again to the GridView
.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"/>