How to sort non-uniform strings that contain numeric values?
-
14-12-2019 - |
Question
I'm having some trouble getting a GridView column of strings to sort properly.
The type of values in the column look like: $99,999, $200, /500, /50,000
Basically non-decimal currency values that may have a '/' instead of a '$'
Does anyone have a good approach to sorting these?
Solution
You could create a sort function that takes a set of strings, removes the first character, then sorts as normal. This would remove the $ or / issue.
To elaborate: create a new iComparer, and then have it return whether string1.SubString[1] > string2.SubString[1]. I'd write a bit of code, but I'm currently away from a computer with VS or Mono on it.
OTHER TIPS
Realized I can just set the sort expression of the BoundField to a different hidden column on the gridview (which contains the amount in a uniform itemCD string). Doh!