Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
Hi,
I would like to know if it's possible to order by a children (or even grand-children) value, like:
foreach (var item in items.Children.Where(x => x.IsVisible().OrderBy(x => x.Value("foo"))) {...}
except "foo" value lives in a child node.
Hey Levente,
Thats exactly how you do it, what you may be missing is the cast inside the loop try:
items.Children.Where(x => x.IsVisible()).OrderBy(x => x.Value<string>("foo"))
There was also a missing bracket to close your Where after IsVisible()
Thanks Ric for the quick answer. It was my bad, the looked value lives in a grand-child node. It's an integer btw.
Is it possible with grand-child node somehow?
I'm not 100% sure what you are trying to achieve, it may be that you need to do some code to order the items before the foreach loop.
But you could try
items.Children.Where(x => x.IsVisible()).OrderBy(x => x.Children.Select(y => y.Value<int>("foo")))
Thank you.
I tried, but it gave me this error:
At least one object must implement IComparable.
Anyway, I'll keep trying.
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
foreach order by children
Hi,
I would like to know if it's possible to order by a children (or even grand-children) value, like:
except "foo" value lives in a child node.
Hey Levente,
Thats exactly how you do it, what you may be missing is the cast inside the loop try:
There was also a missing bracket to close your Where after IsVisible()
Thanks Ric for the quick answer. It was my bad, the looked value lives in a grand-child node. It's an integer btw.
Is it possible with grand-child node somehow?
I'm not 100% sure what you are trying to achieve, it may be that you need to do some code to order the items before the foreach loop.
But you could try
Thank you.
I tried, but it gave me this error:
Anyway, I'll keep trying.
is working on a reply...