日期:2014-05-17 浏览次数:20451 次
dv = new DataView(dt); //筛选(相当于select * from tabMenu where menuParentID = 传入的 parentID) dv.RowFilter = "[Privilege_ID]" + parentID; //用foreach遍历dv foreach (DataRowView row in dv) { //第一次加载时为空 if (node == null) { //创建根节点 TreeNode root = new TreeNode(); //必须与数据库的对应 root.Text = row["Description"].ToString(); root.Value = row["Parent_id"].ToString(); //添加根节点 this.TreeView1.Nodes.Add(root); //递归调用方法本身 CreateTree(int.Parse(row["Parent_id"].ToString()), root, dt, treeView); } else { //添加子节点 TreeNode childNode = new TreeNode(); childNode.Text = row["Description"].ToString(); childNode.Value = row["Parent_id"].ToString(); node.ChildNodes.Add(childNode); CreateTree(int.Parse(row["Parent_id"].ToString()), childNode, dt, treeView); } }