im using the nodefactory to display children of a specified node:
Node node = new umbraco.presentation.nodeFactory.Node(1125);
Nodes childrenNodes = node.Children;
RptDisplayResults.DataSource = childrenNodes;
RptDisplayResults.DataBind();
this works fine. But i need to display the children of these children as well. Basically every node including grandchildren of the specified node. How can i do this?
public void MethodWhereIFilledTheList() { Node parentNode = new umbraco.presentation.nodeFactory.Node(1125); List<Node> myList = new List<Node>(); AddChildNodes(myList, parentNode); }
public void AddChildNodes(List<Node> list, Node parentNode) { for each (Node child in parentNode.Children) { list.Add(child); AddChildNodes(list, child); } }
or how about an xpath expression with the the following method:
public static List<Node> GetNodesFromXpath(string xPath) { List<Node> nodes = new List<Node>();
XPathNavigator xPathNavigator = umbraco.content.Instance.XmlContent.CreateNavigator(); //get all umbraco xml XPathNodeIterator xPathNodeIterator = xPathNavigator.Select(xPath); //TODO: check xpath string is valid
int id; Node node;
while (xPathNodeIterator.MoveNext()) { if (int.TryParse(xPathNodeIterator.Current.Evaluate("string(@id)").ToString(), out id)) //check id is a numberic { node = new Node(id); if (node != null) { nodes.Add(node); } } }
display children of children
im using the nodefactory to display children of a specified node:
Node node = new umbraco.presentation.nodeFactory.Node(1125);
Nodes childrenNodes = node.Children;
RptDisplayResults.DataSource = childrenNodes;
RptDisplayResults.DataBind();
Is there anyone who has an answer to this pleeeease?
Out of my mind some code with recursion:
hth, Thomas
or how about an xpath expression with the the following method:
is working on a reply...