The javascript control ASP.NET treeview control selects or cancels the of sample code


<script language="javascript">  
/*  
 The name of the function :CheckNode(currentNode) , ParentNode(currentNode) , ChildNode(currentNode)  
 The functionality : Realize the belt checkbox the treeview In the   
1 , all children of selected parent nodes are also selected   
2 , after canceling the selection of all child nodes, the selection of parent node is cancelled   
 Method of use :
1 And in the <head></head> In the middle add CheckNode(currentNode) , ParentNode(currentNode) , ChildNode(currentNode)  
2 And in the *.aspx.cs the Page_load() Add in event yourTreeView.Attribute.Add("OnCheck","CheckNode(yourTreeView.getTreeNode(yourTreeView.clickedNodeIndex))")  
  */  

  //Recursively traverses all child nodes & NBSP;  
  function   CheckNode(currentNode)  
  {  
  var   childNode=new   Array();  
  var   parentNodeChild=new   Array();  
  var   isChecked;  
  childNode=currentNode.getChildren();  
  if(currentNode.getAttribute('checked'))  
  {  
  isChecked=true;  
  }  
  else  
  {  
  isChecked=false;  
  }  
  //Parent processing & NBSP;  
  if(currentNode.getParent()!=null)  
  {  
  //Check handle & NBSP;  
  if(currentNode.getAttribute('Checked'))  
  {  
  ParentNode(currentNode);  
  }  
  else  
  //Uncheck & NBSP;  
  {  
  ChildNode(currentNode);  
  }  
  }  
  else  
  {  
  //Doing nothing & NBSP;  
  }  
  //Child node processing & NBSP;  
  if(childNode.length>0)  
  {  
  for(var   i=0;i<childNode.length;i++)  
  {  
  childNode.setAttribute("Checked",isChecked);  
  if(childNode.getChildren().length>0)  
  {  
  CheckNode(childNode);  
  }  
  }  
  }  

  }  
  //Recursively select the parent node & NBSP;  
  function   ParentNode(currentNode)  
  {  
  if(currentNode.getParent()!=null)  
  {  
  currentNode.getParent().setAttribute('Checked',true);  
  //ParentNode(currentNode) is called recursively to iterate over the ParentNode & NBSP; further up;  
  ParentNode(currentNode.getParent());  
  }  
  }  
  //Recursively deselect the parent node & NBSP;  
  function   ChildNode(currentNode)  
  {  
  if(currentNode.getParent()!=null)  
  {  
  var   checkedCount=0;  
  var   childNode=currentNode.getParent().getChildren();  
  for   (var   i=0;i<childNode.length;i++)  
  {  
  if(childNode.getAttribute('Checked'))  
  {  
  checkedCount++;  
  }  
  }  
  if(checkedCount==0)  
  {  
  currentNode.getParent().setAttribute('Checked',false);  
  }  
  //Recursively call ChildNode(currentNode) to iterate over the parent node & PI further up;  
  ChildNode(currentNode.getParent());  
  }  
  }  

</script>

Js recursively traverses the problem of all children of a node in the treeview

 var   AllRootNode=new   Array();  
    AllRootNode=TreeView1.getChildren();  
    AlertNode(AllRootNode);        

    function   AlertNode(NodeArray)  
    {  
      if(parseInt(NodeArray.length)==0)  
        return;  
      else  
      {  
        for(i=0;i<NodeArray.length;i++)  
        {  
          var   cNode;  
          cNode=NodeArray;  
          alert(cNode.getAttribute("Text"));  
          if(parseInt(cNode.getChildren().length)!=0)  
            AlertNode(cNode.getChildren());          
        }  
      }  
    }