private void InitTree(DataTable dt) { tree = new List <TreeNode>(); int deep = 0; do { DataRow[] rows = dt.Select(string.Format("deep={0}", deep)); if (rows.Length == 0) { break; } foreach (DataRow row in rows) { TreeNode node = new TreeNode(row); if (deep == 0)//插入根节点 { tree.Add(node); } else//插入普通节点 { TreeNode parent = FindNodeById(Convert.ToInt32(row["parentId"].ToString())); if (parent == null) { continue; } parent.children.Add(node); } } deep++; } while (true); string range = ""; foreach (TreeNode node in tree) { if (node.children.Count == 0) { range += node.id + ","; } } DataSet ds = UserInfoManage.getUserTree(range); if (ds != null) { foreach (DataRow row in ds.Tables[0].Rows) { TreeNode node = new TreeNode(row["userName"].ToString(), Convert.ToInt32(row["userId"])); TreeNode parent = FindNodeById(Convert.ToInt32(row["departmentId"])); parent.children.Add(node); } } }