private void TreeBind() { var manager = context.dt_manager.FirstOrDefault(w => w.id == GetAdminInfo().id); var department = context.li_departments.FirstOrDefault(w => w.id == manager.department_id); BLL.department bll = new BLL.department(); var dt = new DataTable(); if (department == null) { dt = bll.GetList(0); } else if (department.parent_id == 0) { dt = bll.GetListByOkParentId(department.id, 0); } else { dt = bll.GetListByOkId(department.id, 0); } this.ddlDepartments.Items.Clear(); this.ddlDepartments.Items.Add(new ListItem("不限", "")); foreach (DataRow dr in dt.Rows) { string Id = dr["id"].ToString(); int ClassLayer = int.Parse(dr["class_layer"].ToString()); string Title = dr["department_name"].ToString().Trim(); if (ClassLayer == 1) { this.ddlDepartments.Items.Add(new ListItem(Title, Id)); } else { Title = "├ " + Title; Title = Utils.StringOfChar(ClassLayer - 1, " ") + Title; this.ddlDepartments.Items.Add(new ListItem(Title, Id)); } var g = context.li_user_group_departments.Where(w => w.department_id == Convert.ToInt32(Id)) .Select(s => s.user_group_id) .ToList(); if (groupIdList.Count == 0) { groupIdList = g; } else { groupIdList = groupIdList.Concat(g).ToList(); } departmentIdList.Add(int.Parse(Id)); } }