Copied to clipboard

Flag this post as spam?

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


  • Al Gilson 7 posts 27 karma points
    Aug 13, 2010 @ 21:29
    Al Gilson
    0

    Newbie - best way to load nodes into a dropdown?

    Been looking for some code samples, but couldn't find any that match what I'm looking for, sorry. What's the most efficient way to load children nodes into a dropdown list in a .net macro?

    For example, I can do:

                Node myNode = new Node(1136);
                Nodes myNodeSubpages = myNode.Children;

                foreach (Node nodeValue in myNodeSubpages)
                {

                     // do my drop down list magic here with nodeValue.Name

                }

    Is there a better way that doesn't require me hardcoding the node id into it?

    Could someone share a way to use XPathNavigator to load info of my "mainContent" node in C#? Which way is more efficient?

    Thanks,

    - Al

     

     

  • Darren Ferguson 1022 posts 3259 karma points MVP c-trib
    Aug 14, 2010 @ 09:59
    Darren Ferguson
    0

    In what context are you displaying your dropdown?  front end? back office? and are you having specific issues relating to performance?

    You don't want to hardcode the parent Id - so you'll need to answer the questions above to allow us to help you out.

    As always, please include the version of Umbraco you are using plus OS/DB in case there are any version specific quirks to be aware of.

     

  • Al Gilson 7 posts 27 karma points
    Aug 14, 2010 @ 18:48
    Al Gilson
    0

    Guess that's kind of pertinent. We're running Umbraco 4.5.1, .net 3.5 on Win Server 2003 pulling from a SQL Server 2005 and everything is working well and is very quick. I don't want to include any latency when I start programming code, so I'm looking to do efficient code upfront, instead of coming back to fix old code. This drop down will be displayed in the front end, similar to a node navigation drop down. Want to jump to August 2010's content quickly? Pick it in the drop down.

    Thanks!

  • Tom Maton 387 posts 660 karma points
    Aug 16, 2010 @ 09:38
    Tom Maton
    0

    To get the current node i beleive this you would need to use the nodeFactory

    umbraco.presentation.nodeFactory.Node.GetCurrent();

    In your case

    using umbraco.presentation.nodeFactory;

    Node myNode = new Node(Node.GetCurrent());
    Nodes myNodeSubpages = myNode.Children;

    foreach (Node nodeValue in myNodeSubpages)

    { // do my drop down list magic here with nodeValue.Name

    }

    Hope that helps

    Tom

Please Sign in or register to post replies

Write your reply to:

Draft