Copied to clipboard

Flag this post as spam?

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


  • Sherry Ann Hernandez 320 posts 344 karma points
    Apr 10, 2011 @ 10:40
    Sherry Ann Hernandez
    0

    How do I loop trough the nodes using c#

    Is it possible to loop through the nodes like the for-each using c#?

  • Eran Meir 401 posts 543 karma points
    Apr 10, 2011 @ 11:17
    Eran Meir
    0

    you have number of options: you can create a razor script,
    create a usercontrol and use nodeFactory or uql or ucomponents with uQuery 

  • Sherry Ann Hernandez 320 posts 344 karma points
    Apr 10, 2011 @ 11:58
    Sherry Ann Hernandez
    0

    I already have a user control. But how do I do it?

  • jivan thapa 194 posts 681 karma points
    Apr 10, 2011 @ 12:17
    jivan thapa
    0

    try ..

    read nodes first.

    i assume you have list of nodes like this nodes[]; 

    than start to loop.

    foreach(var v in nodes[])

    {

    response.write(v);

    }

  • Rich Green 2246 posts 4008 karma points
    Apr 10, 2011 @ 12:24
    Rich Green
    0

    Sherry,

    The answer depends a lot on the context.

    Do you wish to loop through only published or both published and unpublished nodes?

    Where do you want to loop from, the whole site? current page?

    Rich

  • Sherry Ann Hernandez 320 posts 344 karma points
    Apr 10, 2011 @ 12:46
    Sherry Ann Hernandez
    0

    I will pass the node like this:

    nodeID = dictionary.item.GetDictionaryItem("meeting nodes");

     

    foreach(nodes in Nodes)

    {

     

    }

    I need to loop throug the child nodes of the nodeID.

     

  • Nik Wahlberg 639 posts 1237 karma points MVP
    Apr 11, 2011 @ 00:50
    Nik Wahlberg
    2

    Hi Sherry, the most simple way to do that is by doing something like this:

    // get the node from the supplied nodeId
    Node n = new Node(nodeId);
    
    // loop over the nodefactories children
    foreach (Node node in n.Children)
    {
        // output node name
        return node.Name;
    }

    There are ways to pass in the node ID and I'm not sure that Dictionary Item is the best vehicle. It may be, but if you can describe in greater detail what you are trying to accomplish we may be able to suggest. 

    Thanks,
    Nik

  • Sherry Ann Hernandez 320 posts 344 karma points
    Apr 11, 2011 @ 09:04
    Sherry Ann Hernandez
    0

    What about if I use razor script? will it be much better in terms of flexibility?

  • Ove Andersen 435 posts 1541 karma points c-trib
    Apr 11, 2011 @ 10:17
    Ove Andersen
    0

    Depends on what you want to do with those nodes when you iterate them.

    Complicated jobs are better suited to C#, but simple queries like "get" operations (name, media, etc.) is much easier to use Razor,(or Ruby or Python) or XSLT IMHO.

Please Sign in or register to post replies

Write your reply to:

Draft