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
My News item node has child nodes like so:
When rendered on the page, I want to display in the reverse order:
When a new item is added, it'll be at the bottom of the list in the back office and top of the list on the page. The order can be changed by sorting the items in the back office.
foreach (var vMessageItem in vFolderNode.Children.OrderBy("sortOrder desc"))
which doesn't work.
What is the correct code, please?
Your help would be much appreciated.
Thanking you in anticipation.
foreach (var vMessageItem in vFolderNode.Children.Reverse())
Dennis is spot on, in order to fix the code you supplied you will need to add in a 'key' that you wish to sort them by, in this case we use the node Name. You might wish to use publish date.
foreach (var vMessageItem in vFolderNode.Children.OrderBy(x => x.Name))
This just sorts the method parameters you can use OrderByDesc with this to achieve what Dennis has said.
foreach (var vMessageItem in vFolderNode.Children.OrderByDesc(x => x.Name))
Isn't it OrderByDescending instead of OrderByDesc?
foreach (var vMessageItem in vFolderNode.Children.OrderByDescending(x => x.Name))
What if I do not want to sort all of the children (can be a huge number) every time? What if I want that on every child page creation, the pages will be sorted automatically, so when I query for the children I'll get a sorted list?
is working on a reply...
Write your reply to:
Image will be uploaded when post is submitted