Child node count in root

4 posts, 0 answers
  1. Herman
    Herman avatar
    28 posts
    Member since:
    Jun 2011

    Posted 01 Jul 2011 Link to this post

    Please help i use treeview and want to see the node count in the root ex
    I want to see this before expanding
    Catalogue (3)
    Items (2)
    Services (4)
    ---------------------------------------------------------------------------------------------------------------------------------------------
    Tree look like this

    Catalogue
            Catalogue one
                    Catalogue two
                            Catalogue three
    Items    
          Item one
                Item Twee
    Services 
        Services one
                Services two
                        Service three
                                Service four
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 01 Jul 2011 Link to this post

    Hello Herman,

    Try the following code snippet in page load to achieve your requirement.
    C#:
    protected void Page_Load(object sender, EventArgs e)
        
            if (!Page.IsPostBack)
            {
                foreach (RadTreeNode node in RadTreeView3.GetAllNodes())
                {
                    if (node.Nodes.Count > 0)
                        node.Text = node.Text + " (" + node.Nodes.Count.ToString() + ")";
                }
            }

    Thanks,
    Shinu.
  3. Herman
    Herman avatar
    28 posts
    Member since:
    Jun 2011

    Posted 01 Jul 2011 Link to this post

    Thanks for replay but the create the following

    Catalogue (1)
        Catalogue one (1)
            Catalogue two (1)
                Catalogue three
    I want

    Catalogue (3)
        Catalogue one  
            Catalogue two 
                Catalogue three
  4. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 01 Jul 2011 Link to this post

    Hello Herman,

    You can achieve this by checking the node level. Here is the modified code.
    C#:
    if (!Page.IsPostBack)
    {
       foreach (RadTreeNode node in RadTreeView1.GetAllNodes())
       {
         if (node.Nodes.Count > 0 && node.Level==0)
         node.Text = node.Text + " (" + node.Nodes.Count.ToString() + ")";
       }
     }

    Thanks,
    Shinu.
Back to Top