Actions of a checkbox in the asp.net2.0 permission tree

Source: Internet
Author: User
Tags count tagname
asp.net

This uses the Asp.net2.0 TreeView control to implement some of the permissions tree's functions in conjunction with JavaScript.
Suppose there are three rules in the permission tree:
1, the node can be accessed, then his parent node will also be able to access;
2, the node can be accessed, then his child nodes can also be accessed;
3, the node is inaccessible, and his child nodes are inaccessible.

The code is as follows:
Gets the parent element of the element-specified tagname
function Public_getparentbytagname (element, TagName)
{
var parent = Element.parentnode;
var uppertagname = Tagname.touppercase ();
If this element is not the desired tag, continue to trace
while (Parent && (Parent.tagName.toUpperCase ()!= uppertagname))
{
Parent = Parent.parentnode? Parent.parentNode:parent.parentElement;
}
return to parent;
}

Set the parent node of the node cheched--the node is accessible, his parent node will also be able to access
function setparentchecked (objnode)
{
var objparentdiv = Public_getparentbytagname (Objnode, "div");
if (Objparentdiv==null | | objparentdiv = = "undefined")
{
Return
}
var ObjID = Objparentdiv.getattribute ("ID");
ObjID = objid.substring (0,objid.indexof ("Nodes"));
ObjID = objid+ "CheckBox";
var objparentcheckbox = document.getElementById (ObjID);
if (Objparentcheckbox==null | | objparentcheckbox = = "undefined")
{
Return
}
if (objparentcheckbox.tagname!= "INPUT" && objparentcheckbox.type = = "checkbox")
Return
Objparentcheckbox.checked = true;
Setparentchecked (Objparentcheckbox);
}

//Set child nodes of a node uncheched--the node is inaccessible, his child nodes cannot access
function setchildunchecked (divid)
{
    var Objchild = Divid.children;
    var count = objchild.length;
    for (var i=0;i<objchild.length;i++)
    {
         var tempobj = objchild[i];
        if (tempobj.tagname== "INPUT" && tempobj.type = = "checkbox")
        {
             tempobj.checked = false;
       }
        setchildunchecked (tempobj);
   }
}

Set the child nodes of a node cheched--the node can be accessed, and his child nodes can also access
function setchildchecked (divid)
{
var objchild = Divid.children;
var count = objchild.length;
for (Var i=0;i<objchild.length;i++)
{
var tempobj = objchild[i];
if (tempobj.tagname== "INPUT" && tempobj.type = = "checkbox")
{
Tempobj.checked = true;
}
Setchildchecked (Tempobj);
}
}

Triggering events
function Checkevent ()
{

var objnode = event.srcelement;

if (objnode.tagname!= "INPUT" | | | objnode.type!= "checkbox")
Return

if (objnode.checked==true)
{
Setparentchecked (Objnode);
var ObjID = Objnode.getattribute ("ID");
var ObjID = objid.substring (0,objid.indexof ("checkbox"));
var objparentdiv = document.getElementById (objid+ "Nodes");
if (Objparentdiv==null | | objparentdiv = = "undefined")
{
Return
}
Setchildchecked (OBJPARENTDIV);
}
Else
{
var ObjID = Objnode.getattribute ("ID");
var ObjID = objid.substring (0,objid.indexof ("checkbox"));
var objparentdiv = document.getElementById (objid+ "Nodes");
if (Objparentdiv==null | | objparentdiv = = "undefined")
{
Return
}
Setchildunchecked (OBJPARENTDIV);
}
}

Then bind the TreeView to the JS event in the Page_Load event:

This. TREEVIEW1.ATTRIBUTES.ADD ("onclick", "checkevent ()");



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.