权限分配(级联复选框操作)

页面前台

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="role_allot.aspx.cs" Inherits="Web.users.role_allot" %>




   
   
   


   


   
       
           
           
       
       
           
           
       
       
           
           
       
       
           
           
       
   

                角色名称 :
           

               
           

                角色说明 :
           

               
           

                IS_delete :
           

               
           

                角色权限 :
           

               

                   

                       
                           
                               

                                   


                                        "
                                            οnclick="Menu1Checked(this);" /><%#Eval("name")%>
                                   


                                   
                                       
                                           


                                                "
                                                    οnclick="Menu2Checked(this);" /><%# Eval("name")%>
                                           


                                           
                                               
                                                   

                                                        "
                                                            οnclick="Menu3Checked(this);" /><%# Eval("name")%>
                                                   

                                               

                                           

                                       

                                   

                               

                           

                       

                   

                   

                                                    OnClientClick="return CheckRoleName();" Text="确定" />
                                                    value="取消" />
                   

               

           

   
   
   
   
    



cs 页面


using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL;
using COMMON;
using Model;


namespace Web.users
{
    public partial class role_allot : System.Web.UI.Page
    {
        public function_btBll bll = new function_btBll();
        public purviewBll pbll = new purviewBll();
        public roleBll rbll = new roleBll();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindSource();            
            }            
        }

        private void BindSource()
        {
            RepMenu1.DataSource = bll.GetList(100, " higher_up_id=0 ");
            RepMenu1.DataBind();
        }

        protected void RepMenu1_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                Repeater repMenu2 = e.Item.FindControl("RepMenu2") as Repeater;//找到里层的repeater对象
                //为第二层的Repeater控件绑定ItemDataBound事件
                repMenu2.ItemDataBound += new RepeaterItemEventHandler(repMenu2_ItemDataBound);
                function_btModel rowv = (function_btModel)e.Item.DataItem;//找到关联的数据项
                int menuId = rowv.id; //获取填充子模块的id
                repMenu2.DataSource = bll.GetList(100, string.Format(" higher_up_id ={0} ", menuId));
                repMenu2.DataBind();
            }
        }

        protected void repMenu2_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                DataList dlMenu3 = e.Item.FindControl("dlMenu3") as DataList; //找到里层的DataList对象
                function_btModel rowv = (function_btModel)e.Item.DataItem;//找到关联的数据项
                int moduleId = rowv.id; //获取填充子模块的id
                dlMenu3.DataSource = bll.GetList(100, string.Format(" higher_up_id ={0} ", moduleId));
                dlMenu3.DataBind();
            }
        }

        protected void btnSure_Click(object sender, EventArgs e)
        {
            string menu1 = this.hidMenu1Id.Value;
            string menu2 = this.hidMenu2Id.Value;
            string menu3 = this.hidMenu3Id.Value;

            string strErr = "";
            if (this.txtname.Text.Trim().Length == 0)
            {
                strErr += "name不能为空!\\n";
            }
            if (this.txtremark.Text.Trim().Length == 0)
            {
                strErr += "remark不能为空!\\n";
            }           

            if (strErr != "")
            {
                MessageBox.Show(this, strErr);
                return;
            }

            roleModel mod = new roleModel();
            mod.name = this.txtname.Text;
            mod.remark = this.txtremark.Text;
            mod.add_time = DateTime.Now;
            mod.IS_delete = 1;
            rbll.Add(mod);

            purviewModel mod2 = new purviewModel();
            mod2.function_id = menu1 + "|" + menu2 + "|" + menu3;
            mod2.role_id = rbll.GetList(1, null)[0].id;
            mod2.add_time = DateTime.Now;
            pbll.Add(mod2);

        }


    }
}


你可能感兴趣的:(级联,权限分配)