locked
Custom sort order RRS feed

  • Question

  • I have a field in which contains one of the following values loaded into an object

    Active

    Inactive

    Onhold

    The sort order on this is custom, meaning if sorted ascending it should be

    Active

    Onhold

    InActive

    How do I achieve this using LINQ (Lambda Expressions)?

    Thursday, November 3, 2011 10:57 AM

Answers

  • Hi John;

    Something like this:

    var results = CollectionObjName.OrderBy( f => f.FieldName );

    Where CollectionObjName is the instance of the collection to query and FieldName is the name of the property of the object in the collection.

     


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".
    Thursday, November 3, 2011 3:16 PM

All replies

  • Hi,

    you will need a kind of order property, that you need to define for your items.

    If done, sort by this order property.

    Holger

    Thursday, November 3, 2011 11:12 AM
  • Hi John;

    Something like this:

    var results = CollectionObjName.OrderBy( f => f.FieldName );

    Where CollectionObjName is the instance of the collection to query and FieldName is the name of the property of the object in the collection.

     


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".
    Thursday, November 3, 2011 3:16 PM