This is a migrated thread and some comments may be shown as answers.

Number of child nodes

3 Answers 76 Views
TreeList
This is a migrated thread and some comments may be shown as answers.
Sonia
Top achievements
Rank 1
Sonia asked on 10 Apr 2013, 11:50 AM
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;
 
 
....

3 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 11 Apr 2013, 05:06 AM
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
0
Sonia
Top achievements
Rank 1
answered on 11 Apr 2013, 07:30 AM
Thank you Shinu. It works ok. But is there any possibility to know the number of child items if the node is not expanded?


0
Accepted
Shinu
Top achievements
Rank 2
answered on 12 Apr 2013, 04:28 AM
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
Tags
TreeList
Asked by
Sonia
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Sonia
Top achievements
Rank 1
Share this question
or