Number of child nodes

4 posts, 2 answers
  1. Sonia
    Sonia avatar
    90 posts
    Member since:
    Mar 2012

    Posted 10 Apr 2013 Link to this post

    I need to get the number of child nodes of a treelist node.
    But the instruction item.ChildItems.Count is always zero.
    What I am doing wrong.



        
    protected void RadTreeList1_ItemDataBound(object sender, TreeListItemDataBoundEventArgs e)
        {
            if (e.Item is TreeListDataItem)
            {
                TreeListDataItem item = e.Item as TreeListDataItem;
     
                int numberOfChilds = item.ChildItems.Count;
     
     
    ....
  2. Answer
    Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 11 Apr 2013 Link to this post

    Hi,

    Try the following code.
    c#:
    protected void TreeList1_PreRender(object sender, EventArgs e)
    {
       foreach (TreeListDataItem item in TreeList1.Items)
       {
          if (item.Expanded)
          {
              int count=item.ChildItems.Count;
          }
       }
    }

    Thanks,
    Shinu
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Sonia
    Sonia avatar
    90 posts
    Member since:
    Mar 2012

    Posted 11 Apr 2013 Link to this post

    Thank you Shinu. It works ok. But is there any possibility to know the number of child items if the node is not expanded?


  5. Answer
    Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 11 Apr 2013 Link to this post

    Hi,

    As far as I know, since expand / collapse operation requires postback the child items are not created if the parent is not expanded. Hope this helps.

    Thanks,
    Shinu
Back to Top