dropdownlist显示树形结构

/// <summary>
        /// 递归
        /// </summary>
        /// <param name="deplist"></param>
        /// <param name="level">制表符分隔符</param>
        /// <param name="filterDepId">过滤的元素</param>
        /// <returns></returns>
        private static List<Department> GetDepList(List<Department> deplist, int level, int filterDepId)
        {
            string tempString = "";
            tempString = tempString.PadRight(level * 2, '');
            List<Department> newList = new List<Department>();
            foreach (Department dep in deplist)
            {
                if (dep.DeptId == filterDepId)
                    continue;
                Department newDep = new Department();
                newDep.Name = tempString + dep.Name;
                newDep.DeptId = dep.DeptId;
                newList.Add(newDep);
                List<Department> children = new BLL.DepartmentMan().GetDepsByParentId(dep.DeptId);
                if (children.Count > 0)
                {
                    newList.AddRange(GetDepList(children, level + 1, filterDepId));
                }
            }
            return newList;
        }

 

posted @ 2015-12-31 15:38  哈哈2222  阅读(699)  评论(2编辑  收藏  举报