Jez wrote:
When using Sorting on a GridView bound to a LLBLGenDataSource2 with LivePersistence disabled I've noticed a couple of things.
Firstly, the SortExpression property on the GridView appears to be case sensitive. Eg If I have a property on my entity called "Surname" then using SortExpression="surname" will not work, it has to be SortExpression="Surname".
When using the ObjectDataSource this is not case sensitive. Is this by design?
Secondly, when the SortExpression is composed of multiple fields (eg SortExpression="Surname, Forename") then the OrderBy clause in the SQL seems to be generated incorrectly when sorting in Descending order, eg:
ORDER BY [dbo].[Students].[Surname] ASC, [dbo].[Students].[Forename] DESC
I believe this should be:
ORDER BY [dbo].[Students].[Surname] DESC, [dbo].[Students].[Forename] DESC
When sorting in Ascending order, the OrderBy clause is generated correctly.
It's case insensitive for the ObjectDataSource as it sorts using a dataview object: it simply plugs the sortexpression as the sort string of the dataview. The problem is: they pass the sortexpression of the column you clicked to the control and append DESC to the expression when it's descending sort but don't append anything if it's an ascending sort.
Now, as you can imagine this is a pretty sucky way of doing it. I mean: why not pass a Dictionary<string, ListSortDirection> ? It's .net 2.0 after all. Because if you sort on 2 columns, say Col1 and Col2, and one has to be ascending and the other descending, what will the string be? Col1, Col2 DESC.
So the datasource control can't figure out which column to apply the DESC to: both or just the last one.
I.o.w.: not solvable.
I've added a case insensitive comparer to the dictionary of field names which is passed to the routine which creates the SortExpression object, so the fieldnames can now be case insensitive. For filters, names have to be case sensitive.