Dataview Sorting RRS feed

  • Question

  • User-822918708 posted

    I've got a dataview with a couple hundred rows in it.

    In C#/.Net3.5, I can walk through this dataview like this (for dataview d):

    for (inti = 0; i < d.Table.Rows.Count; i++){


    And I get the dataview sorted as I epxect from top to bottom.

    But if I do this:

    foreach (DataRow r in d.Table.Select("")){


    I seem to get a different sort order.

    I'd post a more glorious sample but I can't get it to reproduce the issue in a controlled way. Yet in my web page it does it every time.

    My question is:

    How can I maitain the sort order in the orgininal DataView, yet still apply filter criteria to a Table?

    It looks like calling "Select()" with no sort order isn't a guarentee that the order will be maintained?

    I cheked d.Sort and it is "", but the "Select" by default seems to be sorting by the first column for the web page.


    I know I'm fishing with a short pole, but does anyone have any thoughts on this?



    Friday, July 15, 2011 1:52 PM


  • User-822918708 posted

    Got it.

    As often happens when I work on something for 2 days. Once I post, I find it.

    Seems there's a property on the data view called "ApplyDefaultSort". When its set to "true" it can re-sort things when "Select" is called.

    myDataView.ApplyDefaultSort =false;

    Corrects this.





    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, July 15, 2011 2:44 PM

All replies