<p>This is my first real question of need for any of those Gridview experts out there in the .NET world.</p>

<p>I an creating a Gridview from codebehind and I am holding a bunch of numerical data in the columns.  Although, I do add the comma in the number fields from codebehind.  When I load it to the Gridview, I have the sorting ability turned on, BUT the gridview chooses to ALPHA sort rather than sorting numerically because I add in those commas.</p>

<p>So I need help.  Anyone willing to give this one a shot?  I need to change some of my columns in the gridview to numerical sort rather than the alpha sort it is using.</p>

[{'answer_id': 79835, 'author': 'tsimon', 'author_id': 1685, 'author_profile': 'https://Stackoverflow.com/users/1685', 'pm_score': 1, 'selected': False, 'text': '<p>If you do end up implementing your own comparer and sorting them as strings, the algorithm for treating numbers \'properly\' is called Natural Sorting. Jeff wrote a pretty good entry on it here:<br>\n<a href="https://blog.codinghorror.com/sorting-for-humans-natural-sort-order/" rel="nofollow noreferrer">Sorting for Humans : Natural Sort Order</a></p>\n\n<p>You can find a pretty good implementation in C# here:<br>\n<a href="http://www.codeproject.com/KB/string/NaturalSortComparer.aspx" rel="nofollow noreferrer">http://www.codeproject.com/KB/string/NaturalSortComparer.aspx</a></p>\n'}, {'answer_id': 80367, 'author': 'Mitchel Sellers', 'author_id': 13279, 'author_profile': 'https://Stackoverflow.com/users/13279', 'pm_score': 0, 'selected': False, 'text': '<p>Depending on exactly how you are doing sorting you could use one of the above methods, or you could return to the DB and get the sorting done there if the columns are actually a number type, then add your decoration to it later.</p>\n'}, {'answer_id': 97441, 'author': 'TonyOssa', 'author_id': 3276, 'author_profile': 'https://Stackoverflow.com/users/3276', 'pm_score': 0, 'selected': False, 'text': '<p>P-Invoke is your friend.</p>\n\n<pre><code>[DllImport("Shlwapi.dll", CharSet = CharSet.Unicode)]\nprivate static extern int StrCmpLogicalW(string psz1, string psz2);\n</code></pre>\n\n<p>Then you could use it as your own comparer.</p>\n\n<p>For example (in VS2005),</p>\n\n<pre><code>Array.Sort(tringArray, delegate(string left, string right)\n{\n    return StrCmpLogicalW(left, right);\n});\n</code></pre>\n'}, {'answer_id': 668269, 'author': 'SpoiledTechie.com', 'author_id': 7644, 'author_profile': 'https://Stackoverflow.com/users/7644', 'pm_score': 1, 'selected': True, 'text': '<p>Instead, I just resorted to the JQUERY Table Sorter.</p>\n\n<p>can be found here: <a href="http://tablesorter.com/docs/" rel="nofollow noreferrer">tablesorter</a></p>\n'}, {'answer_id': 9037720, 'author': 'Naikrovek', 'author_id': 137427, 'author_profile': 'https://Stackoverflow.com/users/137427', 'pm_score': 0, 'selected': False, 'text': "<p>I realize this is really old, but you're mixing data with presentation; that's what's screwing up the sort.  Get the number out of SQL without adding commas, then add them in the presentation layer.</p>\n"}]
['https://Stackoverflow.com/questions/79736', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/7644/']