Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Phil Crowe 192 posts 256 karma points
    Apr 20, 2010 @ 12:38
    Phil Crowe
    0

    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();

    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?

  • Phil Crowe 192 posts 256 karma points
    Apr 20, 2010 @ 15:17
    Phil Crowe
    0

    Is there anyone who has an answer to this pleeeease?

  • Thomas Höhler 1237 posts 1709 karma points MVP
    Apr 20, 2010 @ 15:33
    Thomas Höhler
    0

    Out of my mind some code with recursion:

    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);
    }
    }

    hth, Thomas

  • Hendy Racher 863 posts 3849 karma points MVP 2x admin c-trib
    Apr 20, 2010 @ 16:01
    Hendy Racher
    1

    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); }
    }
    }

    return nodes;
    }
Please Sign in or register to post replies

Write your reply to:

Draft