Help listing child pages node name in DDL user control c#
Hi all
Sorry if this is a stupid question but I need help displaying child nodes in a drop down list that appears on a user control. I have used the following code and all though it is finding the 10 child pages in my drop down list it is displayig them all as umbraco.presentation.nodefactory.nodes. How can I display the actual node name? I'm new to this sorry
using umbraco.presentation.nodeFactory;
{
public partial class ExampleUserControl : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
//If you need a specific node based on ID use this method (where 123 = the desired node id)
var specificNode = new Node(123);
//To get the children as a Nodes collection use this method
var childNodes = specificNode.Children;
Var myList = new List
//Iterating over nodes collection example
foreach(var node in childNodes)
{
MyList.add(node.toString());
}
MyddL.DataSource = myList;
MyddL.DataBind();
}
}
I have tried what you have suggested but i am getting compiler errors on nodes.Add(node.Id, node.Name); the only things that are available after the period on node are 4 methods and no properties such as id, name etc
Help listing child pages node name in DDL user control c#
Hi all
Sorry if this is a stupid question but I need help displaying child nodes in a drop down list that appears on a user control. I have used the following code and all though it is finding the 10 child pages in my drop down list it is displayig them all as umbraco.presentation.nodefactory.nodes. How can I display the actual node name? I'm new to this sorry
using umbraco.presentation.nodeFactory; { public partial class ExampleUserControl : System.Web.UI.UserControl { protected void Page_Load(object sender, EventArgs e) {
Var myList = new List
}
Thanks
Paul
Hi Paul,
You can use Dictionary or ListItems classes for creating datasource for dropdownlist.
Thanks,
Alexander
Hi Alexander,
thanks for getting back.
I have tried what you have suggested but i am getting compiler errors on nodes.Add(node.Id, node.Name); the only things that are available after the period on node are 4 methods and no properties such as id, name etc
am i missing a namespace?
thanks paul
Hi
I have found a way to make the node properties available I have changed the following from
Var childNodes = specificNode.children
To
Var childNodes = specificNode.childrenAsList
I was then able to access the node properties meaning I could add the name value to myList using the following
MyList.add(node.Name);
Thanks for your help
Paul
is working on a reply...