Treeview unrefresh expansion and contraction

Source: Internet
Author: User

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;
}

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.