I'm trying to pull the latest 5 articles from the news section and then sort them by the article date.
I've managed to get the 5 articles and display them ok, but the OrderBy is not working as expected. I need to sort them by a property on the node called "NewsDate" which is a date picker.
protected void Page_Load(object sender, EventArgs e) { var currentNode = Node.GetCurrent(); var nodeTypeAlias = currentNode.NodeTypeAlias;
if (nodeTypeAlias == "NewsMasterPage") { var nodes = FindChildren(currentNode, t => t.NodeTypeAlias.Equals("NewsArticle")); var nodesOutput = nodes.OrderBy(n => n.GetProperty("NewsDate"));
Trying to OrderBy Date on list returned in C#
I'm trying to pull the latest 5 articles from the news section and then sort them by the article date.
I've managed to get the 5 articles and display them ok, but the OrderBy is not working as expected. I need to sort them by a property on the node called "NewsDate" which is a date picker.
GetProperty will return the value as a string, so you will need to change the type to a date then it should work.
something like this:
is working on a reply...