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

Child node count in NodeDataBound event

2 Answers 84 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Russ
Top achievements
Rank 1
Russ asked on 18 Dec 2010, 05:42 PM

Is a node's child node count available in the NodeDataBound event? 

This code...

protected void RadTreeView1_NodeDataBound(object sender, RadTreeNodeEventArgs e) 
{     
    if (e.Node.Nodes.Count > 0) 
        throw new Exception("bang"); 
}

...never seems to throw an exception. 

It makes sense that it might not have the child nodes count until the tree is fully databound, but I just wanted to make sure that is the case or if I'm overlooking something.

Thanks... Russ

2 Answers, 1 is accepted

Sort by
0
Accepted
Dimitar Terziev
Telerik team
answered on 22 Dec 2010, 04:59 PM
Hello Russ,

By default tree nodes are binded before their child nodes so you can't get child node count when a node is databounded. Your code never throws an exception for this particular reason, the count is always 0 and the condition in the if statement is never fulfilled. If you change it to :
try
       {
           if (e.Node.Nodes.Count == 0)
           {
               throw new Exception();
           }
       }
       catch (Exception ex)
       {
           Response.Write(ex.Message);
       }
an exception will be thrown for every item in the Treeview.

Best wishes,
Dimitar Terziev
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
Russ
Top achievements
Rank 1
answered on 22 Dec 2010, 05:04 PM
Hi Dimitar - That is what I thought the case might be. Just wanted to be sure.

Thanks for your response!

...Russ
Tags
TreeView
Asked by
Russ
Top achievements
Rank 1
Answers by
Dimitar Terziev
Telerik team
Russ
Top achievements
Rank 1
Share this question
or