Copy code The code is as follows: <br>/* <br>Function name: CheckNode(currentNode), ParentNode(currentNode), ChildNode(currentNode) <p>Function: Implement treeview with checkbox <br>1. Select the parent node and all its child nodes will be selected <br>2. After canceling the selection of all child nodes, the selection of the parent node will also follow. Cancel </p> <p>Usage: <br>1. Add CheckNode(currentNode), ParentNode(currentNode), ChildNode(currentNode) in the middle of <head></head> </p> <p>2. Add yourTreeView.Attribute.Add("OnCheck","CheckNode(yourTreeView.getTreeNode(yourTreeView.clickedNodeIndex))") in the Page_load() event of *.aspx.cs <br> */ <br> <br> //Recursively traverse all child nodes <br> function CheckNode(currentNode) <br> { <br> var childNode=new Array(); <br> var parentNodeChild=new Array(); <br> var isChecked; <br> childNode=currentNode.getChildren(); <br> if(currentNode.getAttribute('checked')) <br> { <br> isChecked=true; <br> } <br> else <br> { <br> isChecked=false; <br> } <br> //Parent node processing <br> if(currentNode.getParent()!=null) <br> { <br> //Selected processing <br> if(currentNode.getAttribute ('Checked')) <br> { <br> ParentNode(currentNode); <br> } <br> else <br> //Uncheck <br> { <br> ChildNode(currentNode); <br> } <br> } <br> else <br> { <br> //Do nothing <br> } <br> //Child node processing <br> if(childNode.length>0) <br> { <br> for(var i=0;i<childNode.length;i ) <BR> { <BR> childNode.setAttribute("Checked",isChecked); <BR> if(childNode.getChildren().length>0) <br> { <br> CheckNode(childNode); <br> } <br> } <br> } <br><br> } <br> //Recursively select the parent node <br> function ParentNode(currentNode) <br> { <br> if(currentNode.getParent()!=null) <br> { <br> currentNode.getParent().setAttribute('Checked',true); <br> //Recursively call ParentNode(currentNode) to traverse updates The parent node of the previous layer <br> ParentNode(currentNode.getParent()); <br> } <br> } <br> //Recursively unselect the parent node <br> function ChildNode(currentNode) <br> { <br> if(currentNode.getParent()!=null) <br> { var checkedCount=0; <br> var childNode=currentNode.getParent().getChildren(); <br> for (var i=0; i<childNode.length;i ) <br> { <br> if(childNode.getAttribute('Checked')) <br> { <br> checkedCount ; <br> } <br> } <br> if(checkedCount= =0) <br> { <br> currentNode.getParent().setAttribute('Checked',false); <br> } <br> //Recursively call ChildNode(currentNode) to traverse the higher-level parent node <br> ChildNode (currentNode.getParent()); The problem<br><br><br><br><br>Copy code<br></p> </div> <br> The code is as follows:<br><div class="codebody" id="code83245"> <br> var AllRootNode=new Array(); <br> AllRootNode=TreeView1.getChildren(); <br> AlertNode(AllRootNode); <br><br> function AlertNode(NodeArray) <br> { <br> if(parseInt(NodeArray.length)==0) <br> return; <br> else <br> { <br> for(i=0;i<NodeArray.length;i ) <br> { <br> var cNode; <br> cNode=NodeArray; <br> alert(cNode.getAttribute("Text")); <br> if(parseInt(cNode.getChildren().length)!=0) <br> AlertNode(cNode.getChildren()); <br> } <br> } <br> } <p></p> </div>