Permission Configuration System under asp. net1.1 from design to implementation (3)

Source: Internet
Author: User
How can I use scripts to implement the parent-child node linkage function of TreeView? Due to Firefox's own characteristics, do not use scripts in IE for implementation, and use. cs code for implementation in Firefox. Because these two browsers have poor compatibility, Ai!
Okay, let's talk nonsense. Now, we will first provide the script method for implementing the association of the TreeView parent and child nodes:

Function ChcekFuncNodes (e)
{
Var I = e. clickedNodeIndex;
Var node = e. getTreeNode (I );
Var NodeArray = node. getChildren ();
If (NodeArray. length> 0)
{
If (node. getAttribute ("Checked") = true)
{
For (var I = 0; I <NodeArray. length; I ++)
{
CheckTreeNode (NodeArray [I], true, false );
GetSelectedFunctionPointID (NodeArray [I]);
}
GetSelectedFunctionID (node );
}
Else
{
For (var I = 0; I <NodeArray. length; I ++)
{
CheckTreeNode (NodeArray [I], false, false );
}
}
}
Else
{
Var ParentNode = node. getParent ();
If (ParentNode! = Null)
{
If (node. getAttribute ("Checked") = true)
{
GetSelectedFunctionPointID (node );
CheckTreeNode (ParentNode, true, false );
GetSelectedFunctionID (ParentNode );
}
Else
{
If (AllChildTreeNodeSameCheck (ParentNode, false ))
{
CheckTreeNode (ParentNode, false, false );
}
}
}
Else
{
CheckTreeNode (node, true, false );
GetSelectedFunctionID (node );
}
}
} Function CheckTreeNode (chilNode, isCheck, atuoSetChilTreeNode)
{
 
If (chilNode! = Null)
{
// Alert (chilNode );
ChilNode. setAttribute ('checked', isCheck );
If (atuoSetChilTreeNode)
{
CheckChildTreeNode (chilNode, isCheck)
}
}
} Function CheckChildTreeNode (Pnode, isCheck)
{
If (Pnode! = Null)
{
Var arr = Pnode. getChildren ();
For (var I = 0; I <arr. length; I ++)
{
Arr [I]. setAttribute ('checked', isCheck );
}
}
} Function AllChildTreeNodeSameCheck (PareNode, value)
{
If (PareNode! = Null)
{
Var chids = PareNode. getChildren ();
For (var I = 0; I <chids. length; I ++)
{
If (chids [I]. getAttribute ("Checked ")! = Value)
{
Return false;
}
}
}
Return true;
}

As we all know, there is no need to talk about it. The following two methods are used to record the FunctionID and FunctionPointID selected by the user and pass it. the cs file is used to add why I use document. getElementById ('<% = hidenFunID. clientID %> ') instead of document. getElementById ('hienfunid ')? The reason is that my script is placed in the ascx file (that is, in UserControl), so you can only find the control in this way, otherwise you will not be able to find it! A little trick.

Function GetSelectedFunctionID (nodes)
{
Var hideFun = document. getElementById ('<% = hidenFunID. ClientID %> ');
Var checkFun = hideFun. value;
CheckFun + = nodes. getAttribute ("ID") + ";";
HideFun. value = checkFun;
// Alert (hideFun. value );
} Function GetSelectedFunctionPointID (nodes)
{
Var hideFunPoint = document. getElementById ('<% = txtPointId. ClientID %> ');
Var checkFun = hideFunPoint. value;
CheckFun + = nodes. getAttribute ("ID") + ";";
HideFunPoint. value = checkFun;
// Alert (hideFunPoint. value );
}

In the last step, let the Parent and Child Nodes of the TreeView interact to produce real results ................. private void Page_Load (object sender, System. eventArgs e)
{
If (! Page. IsPostBack)
{
TvRoleFunctions. Attributes. Add ("oncheck", "ChcekFuncNodes (this )");
}
}

Next writing notice:
How to Implement the Select All TreeView function for All nodes? How can we expand and collapse freely?

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.