When rendered on the page, I want to display in the reverse order:
Item 3
Item 2
Item 1
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.
I've tried:
foreach (var vMessageItem in vFolderNode.Children.OrderBy("sortOrder desc"))
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("sortOrder desc"))
Would become:
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))
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?
Sorting children
My News item node has child nodes like so:
News item Item 1 Item 2 Item 3
When rendered on the page, I want to display in the reverse order: Item 3 Item 2 Item 1
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.
I've tried:
which doesn't work.
What is the correct code, please?
Your help would be much appreciated.
Thanking you in anticipation.
Roger
Hi Roger.
Try this:
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.
Would become:
This just sorts the method parameters you can use OrderByDesc with this to achieve what Dennis has said.
Isn't it OrderByDescending instead of OrderByDesc?
like:
Hi all,
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?
Thanks
is working on a reply...