I recently discovered the handy little NullDisplayText property for BoundColumns on the GridView control. This works great for handling NULL values in my recordset – I can display the placeholder “System” when my username field is NULL, for example.
However, for the SortExpression I can only specify the name of the column, as far as I know. So when I sort by that column it’s still sorting using NULL as the value to sort by instead of my custom value, causing those items to show up first in the list. So my results look like this when I sort:
System
System
Adams
Simpson
Any idea how I can customize the SortExpression behavior to use my custom NullDisplayText value instead of the default NULL? Is this something I just need to handle in my SQL?
Thanks!
I think it breaks all sorts of rules because it puts sql in the presentation layer, but I must confess that I have used a case statement in the sort expression before:
You could try
But perhaps you should really do it in the SQL called from the data access layer as you suggested in your question.