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

ServerSide - How to check if node has children?

3 Answers 896 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Andy
Top achievements
Rank 1
Andy asked on 26 Jul 2010, 12:11 AM

Need help with the following:.

I am loading a treeview on pageload.
The user clicks on a button... at serverside I want to insert several new nodes to a Parent Node only if the child nodes does not already exists.

Now I can find the parent node... it exists.  By doing the following I thought I get a count of the "child" nodes.  I am getting 0 (zero) count event though that node (that I found) has child nodes.

 

pNode = rtv.FindNodeByValue(nodeVal.ToUpper(),

true);

 

 

if (pNode != null)

 

{

    int count =  pNode.Nodes.Count

 

 

}

How can I determine if a node has child nodes serverside?
Thanks.

3 Answers, 1 is accepted

Sort by
0
Veronica
Telerik team
answered on 26 Jul 2010, 09:44 AM
Hello Andy,

Yes, one way is to use :

int count = node.Nodes.Count;

However this will return only the next level of nodes which are children of the current node. To be able to get the count of all child nodes there is a new method since Version 2010.2.713 called GetAllNodes().

int count1 = node.GetAllNodes().Count;

Please let me know if you have further questions.

Best Regards,
Veronica Milcheva
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Andy
Top achievements
Rank 1
answered on 26 Jul 2010, 02:40 PM
Thank for your response.

You mention that the following should work... but it does not.  I you look at my  code "snippet"...
I verified that I found "pNode"... and 100% sure that it has child nodes (visually it's there).  Yet the following return zero...

int count = node.Nodes.Count;

I will try your suggestion and hopefully have better luck.
int count1 = node.GetAllNodes().Count;

Thanks again.
0
Veronica
Telerik team
answered on 27 Jul 2010, 10:30 AM
Hello Andy,

If this doesn't help, could you please send me the code you are testing so I can help you?

Thank you!

Best Regards,
Veronica Milcheva
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
TreeView
Asked by
Andy
Top achievements
Rank 1
Answers by
Veronica
Telerik team
Andy
Top achievements
Rank 1
Share this question
or