About ASP: When Treeview selects a parent node, it automatically selects all subnodes. There are many methods on the Internet. The following is a method:
< 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 ) Return ;
VaR Checkboxs = Div. getelementsbytagname ( ' Input ' );
For ( VaR I = 0 ; I < Checkboxs. length; I ++ ){
If (Checkboxs [I]. Type = ' Checkbox ' )
Checkboxs [I]. Checked = Ele. checked;
}
}
}
< / SCRIPT>
There is also a slightly complex requirement below: When a Treeview selects any node, if there are subnodes, it will automatically select (or all are not selected) The subnode, at the same time, determine whether or not to select the parent node or grandfather node. If a child node under the parent node is selected, select the parent node as well. For example, if a sub-menu is selected during menu maintenance, the parent menu must be selected. Otherwise, the parent menu cannot be seen. How can this problem be solved? If you select the corp node, you must automatically select all the above three layers.
Implemented JSCodeAs follows:
The code is mainly added with the bold part: (three layers are judged up)
< 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 ){
}
Else {
VaR Checkboxs = Div. getelementsbytagname ( ' Input ' );
For ( VaR I = 0 ; I < Checkboxs. length; I ++ ){
If (Checkboxs [I]. Type = ' Checkbox ' )
Checkboxs [I]. Checked = Ele. checked;
}
}
VaRParentdiv= Event. srcelement. parentelement. parentelement;
VaRParentparentdiv= event. srcelement. parentelement. parentelement. parentelement. parentelement. parentelement. parentelement;
var parentparentparentdiv = event. srcelement. parentelement. parentelement. parentelement. parentelement. parentelement. parentelement. parentelement;
If (parentdiv ! = null & parentdiv ! = undefined) {
var parentcheckboxid = parentdiv. id. replace ( ' nodes ' , ' checkbox ' );
VaRCheckboxs=Parentdiv. getelementsbytagname ('Input' );
VaRChildnodechecked= False ;< br> for ( var I = 0 ; I checkboxs. length; I ++ ){
If(Checkboxs [I]. Type= 'Checkbox' && Checkboxs [I]. Checked)
Childnodechecked= True ;
}
If(Document. getelementbyid (parentcheckboxid)! = Null ){
Document. getelementbyid (parentcheckboxid). Checked= childnodechecked;
}< BR >}< br> If (parentparentdiv ! = null & parentparentdiv ! = undefined) {
var parentparentcheckboxid = parentparentdiv. id. replace ( ' nodes ' , ' checkbox ' );
VaRCheckboxs=Parentparentdiv. getelementsbytagname ('Input' );
VaRChildnodechecked= False ;< br> for ( var I = 0 ; I checkboxs. length; I ++ ){
If(Checkboxs [I]. Type= 'Checkbox' && Checkboxs [I]. Checked)
Childnodechecked= True ;< BR >}
If (document. getelementbyid (parentparentcheckboxid) ! = null ) {
document. getelementbyid (parentparentcheckboxid ). checked = childnodechecked;
}< BR >}
If (parentparentparentdiv ! = null & parentparentparentdiv ! = undefined) {
var parentparentparentcheckboxid = parentparentparentdiv. id. replace ( ' nodes ' , ' checkbox ' );
VaRCheckboxs=Parentparentparentdiv. getelementsbytagname ('Input' );
VaRChildnodechecked= False ;< br> for ( var I = 0 ; I checkboxs. length; I ++ ){
If(Checkboxs [I]. Type= 'Checkbox' && Checkboxs [I]. Checked)
Childnodechecked= True ;
}
If(Document. getelementbyid (parentparentparentcheckboxid)! = Null ){
Document. getelementbyid (parentparentparentcheckboxid). Checked= Childnodechecked;
}
}
}
}
< / SCRIPT>