Scripting All-in-a-choice operation ASP. NET TreeView control

Source: Internet
Author: User
Tags tagname

1 //tree node tick (cancel) upper automatic all check (cancel) subordinate, check the lower level automatically check the superior, cancel all subordinate, automatically cancel the superior2 3          //Event Response Function4          varHandlecheckbox =function () {5              //gets the element that triggered the event, because the function is triggered whenever a tree control is clicked, so it must be judged that it only continues when you click the checkbox6              varelement =event.srcelement;7              if(Element.tagname = = "INPUT" && element.type = = "checkbox") {8                  varCheckedstate =element.checked;9                  //take the parent table of the checkbox. The Microsoft TreeView tree is present in the form of a single div wrapped with a single table in each sibling node.Ten                   while(Element.tagname! = "TABLE") { Oneelement =element.parentelement; A                  } -                  varParentelement =element; -  the                  //If the checkbox is selected, determine if the parent checkbox should be automatically selected -                  if(checkedstate) { - checkparents (element); -                  } +  -                  //Takes the element that follows the same level of the element's parent element +element =element.nextsibling; A  at                  if(Element! =NULL) { -                      varChildtables = Element.getelementsbytagname ("TABLE"); -  -                       for(varTableindex = 0; Tableindex < Childtables.length; tableindex++) { - checktable (Childtables[tableindex], checkedstate); -                      } in                  } -                  if(Checkedstate = =false) { to uncheckparents (parentelement); +                  } -  the              } *          } $          //determine and tick the parent checkboxPanax Notoginseng          functioncheckparents (table) { -              //first of all, judging the element has no checkbox,table of the column three that is two there is no the              if(Table = =NULL|| Table.rows[0].cells.length = = 2)//This is the root +              { A                  return; the              } +              //takes the element to the front of the same level as the element's parent element -              varParentTable =table.parentElement.previousSibling; $              varCheckedcount =Getcheckedcount (table.parentelement); $              varChildCount =Getchildrencount (table.parentelement); -              if(Checkedcount = =ChildCount) { -                  //Tick Parent element theCheckTable (ParentTable,true); -              }Wuyi              //Iterative Functions the checkparents (parenttable); -          } Wu  -          //To determine and cancel a parent checkbox About          functionuncheckparents (table) { $  -              if(Table = =NULL|| Table.rows[0].cells.length = = 2)//This is the root -              { -                  return; A              } +              varParentTable =table.parentElement.previousSibling; the              //determine the number of child nodes selected -              //determine the number of child nodes selected $              varCheckedcount =Getcheckedcount (table.parentelement); the              varChildCount =Getchildrencount (table.parentelement); the              if(Checkedcount <ChildCount) { theCheckTable (ParentTable,false); the              } -              //Iteration in uncheckparents (parenttable); the          } the  About          //tick or cancel a checkbox the          functionchecktable (table, checked) { the              //to ensure that the last column of the row that is taken to the table (the TreeView is extracted by placing input in the last column of the table row) the              varCheckboxindex = table.rows[0].cells.length-1; +              varCell = Table.rows[0].cells[checkboxindex]; -              //Take to CheckBox the              varcheckboxes = Cell.getelementsbytagname ("INPUT");Bayi              if(Checkboxes.length = = 1) { thecheckboxes[0].checked =checked; the              } -  -          } the  the          //determine the number of child nodes the          functionGetchildrencount (table) { the              varCheckedcount = 0; -              varelement =table.nextsibling; the              varChildTable = table.getelementsbytagname ("table"); the  the               for(varTableindex = 0; Tableindex < Childtable.length; tableindex++) {94                  varChildtables =Childtable[tableindex]; the                  varCheckboxindex = childtables.rows[0].cells.length-1; the                  varCell = Childtables.rows[0].cells[checkboxindex]; the                  varcheckboxes = Cell.getelementsbytagname ("INPUT");98                  if(Checkboxes.length = = 1) { Aboutcheckedcount++; -                  }101              }102              returnCheckedcount;103          }           104          //determine the number of child nodes selected the          functionGetcheckedcount (table) {106              varCheckedcount = 0;107              varelement =table.nextsibling;108              varChildTable = table.getelementsbytagname ("table");109  the               for(varTableindex = 0; Tableindex < Childtable.length; tableindex++) {111                  varChildtables =Childtable[tableindex]; the                  varCheckboxindex = childtables.rows[0].cells.length-1;113                  varCell = Childtables.rows[0].cells[checkboxindex]; the                  varcheckboxes = Cell.getelementsbytagname ("INPUT"); the                  if(Checkboxes.length = = 1 && checkboxes[0].checked = =true) { thecheckedcount++;117                  }118              }119              returnCheckedcount; -}

Called directly when calling the

Handlecheckbox can do it.

Scripting All-in-a-choice operation ASP. NET TreeView control

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.