Sorting Datagrid With Hyphen / Dash

Ask a Question related to ASP.NET Data Grid Control, Design and Development.

  1. #1

    Default Re: Sorting Datagrid With Hyphen / Dash

    Due to their sequence in the ASCII set, - (hyphen) comes before the
    numbers.
    One way you can get around this behavior is to replace the hyphens with
    underscore(_) character and do comparison.

    If you change the hyphens to underscore, then you will need to revert
    the changes once you are done - this you may not like so much.

    To overcome this you can implement a class that implements the
    IComparator interface and pass it along to the sort mechanism - the
    IComparator instance can read the strings replace hyphen to underscore
    and then compare. This will not require a change of your original data
    and hence may be a cleaner solution - except for the fact that you need
    to create another class.

    Samuel Kim Guest

  2. Similar Questions and Discussions

    1. Datagrid sorting
      I have read most messages in regard with this topic, and have tried every measure suggested. I'm still haveing problem to get it to work....
    2. Sorting in the DataGrid
      It's like this: a column in a DataGrid(u know, the component) receives several numbers from an XML,one for each cell, numbers from 0 to 11. Each nr...
    3. DataGrid Not Sorting
      My web datagrid isn't sorting at all. I have it wired up to a handler, and I know the handler is working (being called), but no sorting. The page...
    4. sorting a datagrid
      In asp.net I have created a datagrid which it data source is determined at runtime. How can add the auto sort functionality to this datagrid? In...
    5. Sorting in a DataGrid with no headings
      I have got a scrollable datagrid within a Div tag and a fixed header created using an HTML table. I would like to be able to sort the datagrid by...
  3. #2

    Default Re: Sorting Datagrid With Hyphen / Dash

    Thanks for your answer, I kind of understand what you are saying, but do you
    have any code samples that would make it a little clearer?

    However, this still does not really explain exactly what is going on with
    the sorting at the moment.
    ie

    30-199
    30-299
    303-01
    303-02
    30-399
    30-499

    Regardless of the ASCII value of the hyphen, this sort order is WRONG, all
    the '30-' codes should be together, and all the '303' codes should be
    together. This sequence only makes sense if you ignore the hyphen completly,
    ie:

    30199
    30299
    30301
    30302
    30399
    30499

    Therefore, I draw the conclusion that tha DataGrid treats the hyphen as a
    'special' character for the purposes of sorting. I guess this is because if
    you were sorting proper words you would want (say) 'co-operative' to be
    sorted next to 'cooperative'. But surely this behaviour should be
    controllable...?? :-/

    ALL I want is a way of getting the DataGrid (or DataView) to sort the data
    with a proper ASCII sort, without any 'special casing' being applied to any
    of the characters...

    Anyone got any suggestions on that??

    Cheers,

    Chris.


    "Samuel Kim" <look341@gmail.com> wrote in message
    news:1110325517.500209.265740@o13g2000cwo.googlegr oups.com...
    > Due to their sequence in the ASCII set, - (hyphen) comes before the
    > numbers.
    > One way you can get around this behavior is to replace the hyphens with
    > underscore(_) character and do comparison.
    >
    > If you change the hyphens to underscore, then you will need to revert
    > the changes once you are done - this you may not like so much.
    >
    > To overcome this you can implement a class that implements the
    > IComparator interface and pass it along to the sort mechanism - the
    > IComparator instance can read the strings replace hyphen to underscore
    > and then compare. This will not require a change of your original data
    > and hence may be a cleaner solution - except for the fact that you need
    > to create another class.
    >

    Chris Mayers Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139