I have an Umbraco 4.7 site and have created a search form usercontrol, part of the form has a dropdown called "Location" which lists child nodes of a specific node and then child nodes of that as follows:
Kent - Maidstone - Rochester
Cornwall - Newquay
All works well except I want the dropdown list to be sorted in alphabetical order. Can someone please help me do this with my C# code below, many thanks:
Sort nodes alphabetically in C#
Hi all,
I have an Umbraco 4.7 site and have created a search form usercontrol, part of the form has a dropdown called "Location" which lists child nodes of a specific node and then child nodes of that as follows:
Kent
- Maidstone
- Rochester
Cornwall
- Newquay
All works well except I want the dropdown list to be sorted in alphabetical order. Can someone please help me do this with my C# code below, many thanks:
Change
foreach(Node node in childNodes)
to
foreach(Node node in childNodes.OrderBy(n => n.CreateDate))
Err sorry, I mean:
childNodes.OfType<Node>().OrderBy(n => n.Name)
Hi,
Thanks for the quick response, I tried what you said but it is showing errors in visual studio, this is what I have put:
foreach
(childNodes.OfType<Node
>().OrderBy(n => n.Name))
I am getting "Identifier expected" with regards to"()"
I am also getting "Invalid expression term ')'"
and finally ") expected" regarding the last ")"
This should work though...
foreach(Node node in childNodes.OfType<Node>().OrderBy(n => n.Name))
{
}
Excellent, that works perfectly, thank you very much
is working on a reply...