protected void Page_Load(object sender, EventArgs e)
        {
            
            this.Label1.Text = "";
            this.lbl_ShowErr.Text = "";
            //绑定所有的用户
            //this.UserRightTree.Attributes.Add("onclick", "doCheck()");
            if(!IsPostBack)
            {
            int outrow=0;
            DataSet ds = Y10.BLL.Admin.SystemManager.SystemUserManager_BLL.GetUserList(1, 1000, out outrow);
            dropdownlist1.DataSource = ds.Tables[0];
            dropdownlist1.DataTextField = "realname";
            dropdownlist1.DataValueField = "adminid";
            dropdownlist1.DataBind();
            
            //根据用户权限绑定目录树
            SubBaseIniTreeView(Convert.ToInt32(dropdownlist1.SelectedValue));
            
            }
        }

解决方案 »

  1.   

    /// <summary>
            /// 显示树
            /// </summary>
            private void SubBaseIniTreeView(int userid)
            {
                this.UserRightTree.Nodes.Clear();            //获取有权限用户的树接点
                DataTable dt = Y10.BLL.Admin.Login.dbLogin.GetBackTreeList(userid, 1);            for (int i = 0; i < dt.Rows.Count; i++)
                {
                    TreeNode Node = new TreeNode();
                    Node.Value = dt.Rows[i]["typeid"].ToString();
                    Node.Text = dt.Rows[i]["typename"].ToString();
                    if(!String.IsNullOrEmpty(dt.Rows[i]["adminid"].ToString()))
                    {
                        Node.Checked=true;
                    }                if (Convert.ToInt32(dt.Rows[i]["ptypeid"]) != -1)   //如果不是根节点,递归树
                    {
                        bool blnReturn = false;
                        for (int j = 0; j < this.UserRightTree.Nodes.Count; j++)
                        {
                            blnReturn = IncreaseNode(this.UserRightTree.Nodes[j], Node, dt.Rows[i]["ptypeid"].ToString(), dt.Rows[i]["url"].ToString());                        if (blnReturn)
                                break;
                        }
                    }
                    else  //如果是跟节点直接添加节点
                    {
                        //Node.NavigateUrl = dt.Rows[i]["url"].ToString();
                        //Node.Target = "frame_main";
                        this.UserRightTree.Nodes.Add(Node);
                    }
                }
            }
            /// <summary>
            /// 递规树
            /// </summary>
            /// <param name="parentNode">父节点</param>
            /// <param name="childNode">子节点</param>
            /// <param name="parentID">父节点ID</param>
            /// <param name="url">链接路径</param>
            /// <returns></returns>
            public bool IncreaseNode(TreeNode parentNode, TreeNode childNode, string parentID, string url)
            {
                if (parentNode.Value == parentID)
                {
                    //childNode.NavigateUrl = url;
                    //childNode.Target = "frame_main";
                    parentNode.ChildNodes.Add(childNode);
                    return true;
                }
                else
                {
                    for (int i = 0; i < parentNode.ChildNodes.Count; i++)
                    {
                        IncreaseNode(parentNode.ChildNodes[i], childNode, parentID, url);
                    }
                }            return false;
            }        protected void dropdownlist1_SelectedIndexChanged(object sender, EventArgs e)
            {
                SubBaseIniTreeView(Convert.ToInt32(dropdownlist1.SelectedValue));
            }        protected void Button1_Click(object sender, EventArgs e)
            {
                //先删除该用户以前的所有权限
                Y10.BLL.Admin.SystemManager.UserRightManager_BLL.DeleteRight(Convert.ToInt32(dropdownlist1.SelectedValue));
                
                GetAllNodeText(UserRightTree.Nodes);
                //Response.Write(Label1.Text);
                if (Convert.ToInt32(Y10.BLL.Admin.SystemManager.UserRightManager_BLL.ExcuteInsertOrUpdate(Label1.Text.ToString())) > 0)
                {
                    this.lbl_ShowErr.Text = Y10.Common.Helper.MsgBox.alter("给该用户重新设置权限成功!", "UserRightManager.aspx");
                }
            }        public void GetAllNodeText(TreeNodeCollection tnc)
            {
                foreach (TreeNode node in tnc)
                {
                    GetCheckedNode(node);
                }
            }        private void GetCheckedNode(TreeNode node)
            {
                if (node.Checked)
                {
                    Label1.Text =Label1.Text+ "insert into admin_right_tab(adminid,typeid) values(" + Convert.ToInt32(dropdownlist1.SelectedValue) + ",'" + node.Value + "');";
                }            foreach (TreeNode subnode in node.ChildNodes)
                {
                    GetCheckedNode(subnode);
                }
            }
      

  2.   

    Click the link to solve your problem.Good luck!