Copied to clipboard

Flag this post as spam?

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


  • sukavi 21 posts 41 karma points
    Mar 06, 2012 @ 11:52
    sukavi
    0

    list of all the pages in user control

    hi all ,

    if i have a bellow hierachy of pages in my umbraco  admin panel

    Home

          Story

          SiteMap      

          Shop

                  WebShop

                  MediaShop

          ContactUs

     

     

    now my question is how do i load this same hierachy in to a treeview on my own user control ?

    regards

    suisrad

     

  • sukavi 21 posts 41 karma points
    Mar 06, 2012 @ 13:20
    sukavi
    0

    hi all,

    if i use this code,i can get all the  main pages in my hierachy .... it wont add any child pages  like webshop,MediaShop etc ...

     

     umbraco.presentation.nodeFactory.Node node = new umbraco.presentation.nodeFactory.Node(1070);
                    umbraco.presentation.nodeFactory.Nodes childrenNodes = node.Children;

                    foreach (umbraco.presentation.nodeFactory.Node n in childrenNodes)
                    {
                        TreeView1.Nodes.Add(new TreeNode(n.Name, n.Id.ToString()));
                        TreeView1.DataBind();
                    }

    please help for me to sort this out ?

    regards

    sukavi

     

  • Asif Malik 203 posts 339 karma points
    Mar 06, 2012 @ 14:39
    Asif Malik
    0

    Hi Sukavi. You will need to  make a function which you can recursily call from itself. Something on the lines of

    public void BuildTreeView ( )
    {
        umbraco.presentation.nodeFactory.Node startNode = new umbraco.presentation.nodeFactory.Node ( 1070 );
    
        GetChildren ( startNode );
    
        TreeView1.DataBind ( );
    }
    
    private void GetChildren ( Node startNode )
    {
        foreach ( Node childNode in startNode.Children )
        {
            TreeView1.Nodes.Add ( new TreeNode ( childNode.Name, childNode.Id.ToString ( ) ) );
     
            if ( childNode.Children.Count > 0 )
            {
                GetChildren ( childNode );
            }
        }
    }
  • sukavi 21 posts 41 karma points
    Mar 06, 2012 @ 14:44
    sukavi
    0

    hi asif,

    many thanks for sending me this code, but i am having a compile time error like bellow ? 

    Error    1    The type 'umbraco.interfaces.INode' is defined in an assembly that is not referenced. You must add a reference to assembly 'interfaces, Version=1.0.4085.20549, Culture=neutral, PublicKeyToken=null'.  

     

    here are my full code ....

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using umbraco;
    using umbraco.NodeFactory;


    namespace custom_controls
    {
        public partial class ucpagehierachy : System.Web.UI.UserControl
        {
          
            protected void Page_Load(object sender, EventArgs e)
            {
             
            }

            public void BuildTreeView()
            {
                umbraco.presentation.nodeFactory.Node startNode = new umbraco.presentation.nodeFactory.Node(1070);

                GetChildren(startNode);

                TreeView1.DataBind();
            }

            private void GetChildren(Node startNode)
            {
                foreach (Node childNode in startNode.Children)
                {
                    TreeView1.Nodes.Add(new TreeNode(childNode.Name, childNode.Id.ToString()));

                    if (childNode.Children.Count > 0)
                    {
                        GetChildren(childNode);
                    }
                }
            }
        


        }
    }

  • Asif Malik 203 posts 339 karma points
    Mar 06, 2012 @ 14:47
    Asif Malik
    0

    try adding

    using umbraco.BusinessLogic;
    
  • sukavi 21 posts 41 karma points
    Mar 06, 2012 @ 14:47
    sukavi
    0

    hi asif,

    my umbraco version  is    4.7.1    any idea for this compilation error ?

    thanks

    regards

    sukavi

  • Asif Malik 203 posts 339 karma points
    Mar 06, 2012 @ 14:48
    Asif Malik
    0

    I assume the above didnt help

     Where are you adding this code ? have you created a user control inside the usercontrols folder ? is your project a website, or a web application ?

  • Asif Malik 203 posts 339 karma points
    Mar 06, 2012 @ 14:51
    Asif Malik
    0

    try replacing

    umbraco.presentation.nodeFactory.Node startNode = new umbraco.presentation.nodeFactory.Node(1070);

    with

    umbraco.NodeFactory.Node startNode = new umbraco.NodeFactory.Node(1070);

  • sukavi 21 posts 41 karma points
    Mar 06, 2012 @ 14:52
    sukavi
    0

    hi asif,

    i am writing this code in my own web project,,  once i write my user controls then i copy in to the relavant   umbraco site      /usercontrols    folder and then   copy the .dll file in to the     /bin          directory ...

     

    regards

    sukavi

     

  • sukavi 21 posts 41 karma points
    Mar 06, 2012 @ 14:55
    sukavi
    0

    i have replaced with this

    umbraco.NodeFactory.Node startNode = new umbraco.NodeFactory.Node(1070); 

    but it didnt help me ,     

    compilation error is pointing to the  this method        GetChildren()

     

    regards

    sukavi.

  • Asif Malik 203 posts 339 karma points
    Mar 06, 2012 @ 14:55
    Asif Malik
    0

    ok make sure you have referenced all the necessary DLLs ... in your references folder have you included the right DLLs ? looks like you may have missed out the interfaces dll

  • sukavi 21 posts 41 karma points
    Mar 06, 2012 @ 15:02
    sukavi
    0

    hi asif,

    thanks for the help,

    copilation error gone after i added the interfaces.dll   as a reference , 

     

    but i dont think that recursion logic is right ...its not adding any child nodex to my treeview.... i can see  every pages are coming on same level ,

    any ides ?

    regards

    sukavi

     

  • Asif Malik 203 posts 339 karma points
    Mar 06, 2012 @ 15:09
    Asif Malik
    0

    That was just some quick code, you may want to add them to a global variable and then use that as the datasource for the TreeView,

  • sukavi 21 posts 41 karma points
    Mar 06, 2012 @ 15:26
    sukavi
    0

    thanks for help u r kind i will add my own code to sort it out ... 

    regards

    sukavi ...

     

Please Sign in or register to post replies

Write your reply to:

Draft