Child node count in NodeDataBound event

3 posts, 1 answers
  1. Russ
    Russ avatar
    10 posts
    Member since:
    Sep 2012

    Posted 18 Dec 2010 Link to this post

    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. Answer
    Dimitar Terziev
    Admin
    Dimitar Terziev avatar
    1268 posts

    Posted 22 Dec 2010 Link to this post

    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.
  3. Russ
    Russ avatar
    10 posts
    Member since:
    Sep 2012

    Posted 22 Dec 2010 Link to this post

    Hi Dimitar - That is what I thought the case might be. Just wanted to be sure.

    Thanks for your response!

    ...Russ
Back to Top