I have a gridview that has AllowSorting="true" however I need to implement my own sorting because I have DateTime and Integer data types in several of the columns and I don't want an int column sorted like 1,12,2,23,3,34,4,45,5,56, etc. So, I've added SortParameterName="sortBy" and adjusted my stored procedure to accept this. For only ASC sorting, I've got
ORDER BY
CASE WHEN @.sortBy='' THEN DateCreated END,
CASE WHEN @.sortBy='DateCreated' THEN DateCreated END
and so on. However, columns can also be sorted with DESC. I tried CASE WHEN @.sortBy='DateCreated DESC' THEN DateCreated DESC END, but I get a syntax error on DESC. How can I do this?
If your select is actually returning a datatype of int, it should sort normally. If it's returning an int in a varchar, then well...|||That's not what I was going for. I am using Atlas to do live searching/filtering of the gridview, and in order to use LIKE in my WHERE clause, I had to convert all datatypes to string. I've solved the problem by using
DECLARE @.sort AS varchar(63)
IF (RIGHT(@.sortBy,4)='DESC') BEGIN
SET @.sort=LEFT(@.sortBy,LEN(@.sortBy)-5)
END
ELSE BEGIN
SET @.sort=@.sortBy
END
with what I had before. Then in my code-behind, if "DESC" is part of the param, I start at the bottom of the table and insert rows into a new table.
If
sortBy.EndsWith("DESC")ThenDim dt2As DataTable = dt.CloneFor iAsInteger = dt.Rows.Count - 1To 0Step -1Dim rAs DataRow = dt.Rows(i)dt2.ImportRow(r)
Nextdt = dt2
EndIf
No comments:
Post a Comment