public static DataTable GetDeptData() { string sql = " select * from hr_dept order by orderid asc "; return DBHelper.Instance.ExeDataSet(sql).Tables[0]; } public static void CreateTreeViewRecursive(TreeView tv, DataTable dataSource, int parentid, string url) { CreateTreeViewRecursive(tv.Nodes, dataSource, parentid, url); } private static void CreateTreeViewRecursive(TreeNodeCollection nodes, DataTable dataSource, int parentid, string url) { string filter; filter = string.Format("pid={0}", parentid); //从0开始,可以自设 DataRow[] drarr = dataSource.Select(filter); TreeNode node; foreach (DataRow dr in drarr) { node = new TreeNode(); node.Text = dr["deptname"].ToString(); node.Value = dr["id"].ToString(); node.NavigateUrl = url + "#id=" + dr["id"].ToString(); nodes.Add(node); CreateTreeViewRecursive(node.ChildNodes, dataSource, int.Parse(node.Value), url); } }