Q:

How do I sort an ASP.NET DataGrid by the length of a field?

I have a DataGrid where each column has a SortExpression. I would like the sort expression to be the equivalent of "ORDER BY LEN(myField)".
I have tried 
SortExpression="LEN(myField)" 

but this throws an exception as it is not valid syntax. Any ideas?

A:

What about returning the len by the query already, but don't show that column, only use it as your original column's sortexpression?
I don't think that your idea is supported by default.

A:

Depending on your SQL flavor the following could work:
SELECT
 ColumnA as FieldA
 , ColumnB as FieldB
 , LEN(ColumnA) as FieldL
FROM TableName
ORDER BY L

And then do
SortExpression="FieldL"

