This is my code:
var list = from c in child_categories orderby c.Translated_Syntax
select new { Name = c.Translated_Syntax, ID = c.ID_Category } ;
lst_category.DataSource = list;
lst_category.DataBind();
My list of categories is: Car, Other, Children, House, Girl, Show.
If I order my list, the result it will be:
But I want the 'Other' item to be placed to bottom of list. Something like this:
How can I do this?
You can use this Orderby
-"trick":
from c in child_categories
orderby c.Translated_Syntax == "Other", c.Translated_Syntax
You can remember how it works in this way: the comparison returns a bool
where true
is 1
and false
is 0
. That's why orderby Translated_Syntax == "Other"
will list the "Others" last. If you want it to precede you either have to reverse the condition or (better) use descending
instead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With