footleg

导航

JS实面treeview中选中父节点,子节点也选中

function client_OnTreeNodeChecked()
    {
        var obj = window.event.srcElement;
        var treeNodeFound = false;
        var checkedState;
        if (obj.tagName == "INPUT" && obj.type == "checkbox")
        {
            var treeNode = obj;
            checkedState = treeNode.checked;
            do
            {
             obj = obj.parentElement;
            }
         while (obj.tagName != "TABLE")
            var parentTreeLevel = obj.rows[0].cells.length;
            var parentTreeNode = obj.rows[0].cells[0];
            var tables = obj.parentElement.getElementsByTagName("TABLE");
            var numTables = tables.length
            if (numTables >= 1)
            {
                for (i=0; i < numTables; i++)
                {
                    if (tables[i] == obj)
                    {
                        treeNodeFound = true;
                        i++;
                        if (i == numTables)
                        {
                            return;
                        }
                    }
                    if (treeNodeFound == true)
                    {
                        var childTreeLevel = tables[i].rows[0].cells.length;
                        if (childTreeLevel > parentTreeLevel)
                        {
                            var cell = tables[i].rows[0].cells[childTreeLevel - 1];
                            var inputs = cell.getElementsByTagName("INPUT");
                            inputs[0].checked = checkedState;
                        }
                        else
                        {
                            return;
                        }
                    }
                }
            }
        }
然后加个外观文件TreeView.skin

<asp:TreeView runat="server" BackColor="Linen" NodeIndent="80"  onclick="client_OnTreeNodeChecked();"
                            ShowLines="True" Width="100%" Height="100%">
</asp:TreeView>

<asp:TreeView skinID="treeview1" runat="server" BackColor="Linen" NodeIndent="80" ShowCheckBoxes="All"
onclick="client_OnTreeNodeChecked();"
前台页面引用一下外观文件:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="RoleUpdate.aspx.cs" Inherits="Manager_RoleUpdate" Theme="TreeView"%>
 这里的Theme="TreeView"就是引用外观文件的
                            ShowLines="True" Width="100%" Height="100%">
</asp:TreeView>

posted on 2007-09-29 13:19  迷途  阅读(1736)  评论(0编辑  收藏  举报