Exemplo n.º 1
0
        protected void repRootTree_ItemDataBound1(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                Repeater    rep = e.Item.FindControl("repSubTree") as Repeater;
                DataRowView row = (DataRowView)e.Item.DataItem;

                //获取角色roleid
                int RoleId = 13; //默认匿名用户
                try
                {
                    RoleId = Convert.ToInt32(Session["roleid"].ToString());
                }
                catch { }
                BLL.Base_UserRole userRole = new BLL.Base_UserRole();
                DataTable         dt       = new DataTable();

                //根据用户角色获取模块
                dt           = userRole.GetList(string.Format("RoleId={0}", RoleId)).Tables[0];
                string where = " and NewsTypeId in (";
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    if (i < dt.Rows.Count - 2)
                    {
                        where += dt.Rows[i]["NewsTypeId"].ToString() + ",";
                    }
                    else
                    {
                        where += dt.Rows[i]["NewsTypeId"].ToString();
                    }
                }
                where += " ) ";

                rep.DataSource = bllType.GetList(string.Format("ParentId={0}" + where, row["NewsTypeId"].ToString()));
                rep.DataBind();
            }
        }
Exemplo n.º 2
0
        private void BindData()
        {
            //常见问题
            topMessage.DataSource = bll.GetList(5, "NewsTypeId=45", "CreateDate DESC");
            topMessage.DataBind();

            //获取角色roleid
            int RoleId = 13; //默认匿名用户

            try
            {
                RoleId = Convert.ToInt32(Session["roleid"].ToString());
            }
            catch { }
            BLL.Base_UserRole userRole = new BLL.Base_UserRole();
            DataTable         dt       = new DataTable();

            //根据用户角色获取模块
            dt           = userRole.GetList(string.Format("RoleId={0}", RoleId)).Tables[0];
            string where = " and NewsTypeId in (";
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                if (i < dt.Rows.Count - 2)
                {
                    where += dt.Rows[i]["NewsTypeId"].ToString() + ",";
                }
                else
                {
                    where += dt.Rows[i]["NewsTypeId"].ToString();
                }
            }
            where += " ) ";

            //绑定根节点
            repRootTree.DataSource = bllType.GetList("ParentId=0" + where);
            repRootTree.DataBind();
        }