Copied to clipboard

Flag this post as spam?

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


  • Fredrik Esseen 594 posts 830 karma points
    Nov 18, 2009 @ 10:40
    Fredrik Esseen
    0

    Get level from currentnode in codebehind

    I would like to get the second level from the current node the same way that you do in xslt. I can only get the Parent but I would like to always get the second level of the structure.

  • Dirk De Grave 4537 posts 6006 karma points MVP 3x admin c-trib
    Nov 18, 2009 @ 12:18
    Dirk De Grave
    0

    Hi froad,

    Should be able to do that with node.Children property. Be aware tho if you wish to iterate the child nodes of the current node, first assign the Children property to a new variable and then use foreach to iterate

    var childNodes = nodeFactory.Node.GetCurrent().Children;
    foreach (Node node in childNodes) {...}

     

    Repeat Children property if you need to go two levels deep in the hierarchy.

     

    Hope this helps.

    Regards,

    /Dirk

     

  • Fredrik Esseen 594 posts 830 karma points
    Nov 18, 2009 @ 13:56
    Fredrik Esseen
    0

    But what if I am at third level or lower? How do I get the second level then?

  • Dirk De Grave 4537 posts 6006 karma points MVP 3x admin c-trib
    Nov 18, 2009 @ 15:28
    Dirk De Grave
    1

    Think there's two ways: either via Path property (comma separated list of node ids of parent nodes) or via .Parent property.

     

    Hope this helps.

    Regards,

    /Dirk

  • Fredrik Esseen 594 posts 830 karma points
    Nov 19, 2009 @ 09:14
    Fredrik Esseen
    0

    Solved it by using simple If Else with .Parent. Not the bet way since it is not dynamic. Would be much easier if there was a currentNode.Path.level or something like that.

    Hate to admit that XSLT is more useful in some regards ;)

     

    Thanks for your time Dirk!

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies