1. Of course there is a Treeview. The ID here is namedTreeviewtype
< ASP: Treeview ID = " Treeviewtype " Runat = " Server " Expanddepth = " 1 " > </ ASP: Treeview >
2. Then, two buttons are required.TreeviewexpandcollapseallThis is the js method, which will be introduced later
< Input type = " Button " Value = " Expand " Class = " But1 " Onclick = " Treeviewexpandcollapseall ('<% = treeviewtype. clientid %>', true) " />
< Input type = " Button " Value = " Shrink " Class = " But1 " Onclick = " Treeviewexpandcollapseall ('<% = treeviewtype. clientid %>', false) " />
3. The most critical js method is coming.
/*
* Tree expansion and contraction method 2010-03-23 PM by wqy
* Treeviewid: Tree object
* Expandall: expand or contract
*/
Function treeviewexpandcollapseall (treeviewid, expandall ){
VaR displaystate = (Expandall = True ? " None " : " Block " );
VaR Treeview = Document. getelementbyid (treeviewid );
If (Treeview ){
VaR treelinks = Treeview. getelementsbytagname ( " A " );
VaR nodecount = Treelinks. length;
For (I = 0 ; I < Nodecount; I ++ ){
If (Treelinks [I]. firstchild. tagname ){
If (Treelinks [I]. firstchild. tagname. tolowercase () = " IMG " ){
VaR currenttogglelink = Treelinks [I];
VaR childcontainer = Getparentbytagname ( " Table " , Currenttogglelink). nextsibling;
If (Childcontainer. style. Display = displaystate) {
eval (currenttogglelink. href);
}< BR >}
Function getparentbytagname (parenttagname, childelementobj ){
VaR parent=Childelementobj. parentnode;
While(Parent. tagname. tolowercase ()! =Parenttagname. tolowercase ()){
Parent=Parent. parentnode;
}
ReturnParent;
}