Implements full selection of the checkbox in the Treeview control. After the parent item in the menu selection box is checked, all the subitem selection boxes under the menu are checked. If one of the Child items is not checked, the parent item selection box is blank. For the main effect, see:
The main implementation principle is to use js to select all operations in the onclick event of the Treeview control.
<Script language = "JavaScript" type = "text/JavaScript">
Function ontreenodechecked ()
{
VaR ele = event. srcelement;
If (Ele. type = 'checkbox ')
{
VaR childrendivid = ELE. Id. Replace ('checkbox', 'nodes ');
VaR DIV = Document. getelementbyid (childrendivid );
If (Div! = NULL)
{
VaR checkboxs = div. getelementsbytagname ('input ');
For (VAR I = 0; I <checkboxs. length; I ++)
{
If (checkboxs [I]. type = 'checkbox ')
Checkboxs [I]. Checked = ELE. checked;
}
}
Else
{
VaR DIV = getparentbytagname (Ele, 'div ');
VaR checkboxs = div. getelementsbytagname ('input ');
VaR parentcheckboxid = div. Id. Replace ('nodes ', 'checkbox ');
VaR parentcheckbox = Document. getelementbyid (parentcheckboxid );
For (VAR I = 0; I <checkboxs. length; I ++)
{
If (checkboxs [I]. type = 'checkbox' & checkboxs [I]. Checked)
{
Parentcheckbox. Checked = true;
Return;
}
}
Parentcheckbox. Checked = false;
}
}
}
Function getparentbytagname (element, tagname)
{
VaR parent = element. parentnode;
VaR uppertagname = tagname. touppercase ();
While (parent & (parent. tagname. touppercase ()! = Uppertagname ))
{
Parent = parent. parentnode? Parent. parentnode: parent. parentelement;
}
Return parent;
}
</SCRIPT>
The rest is the onclick event bound to the Treeview control. <Asp: Treeview id = "treeview1" runat = "server" onclick = "ontreenodechecked () "showcheckboxes =" all "expanddepth =" 2 "width =" 100% "Height =" 100% ">
</ASP: Treeview>
So far, we have implemented all the problems of using js to implement full selection and partial selection of the Treeview control.