/// <summary> /// 树行绑定 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void treeviewProductDataBind() { //根节点 DataTable dtCategories = objDs.GetData(); int categoriesLen = dtCategories.Rows.Count; //子节点 DataTable dtProductsCount = objDs.GetDataBy(); int productsLen = dtProductsCount.Rows.Count; //添加根节点 for (int i = 0; i < categoriesLen; i++) { TreeNode treenodeParent = new TreeNode(); treenodeParent.Text = dtCategories.Rows treenodeParent.Value = dtCategories.Rows treenodeParent.NavigateUrl = "Departmen.aspx?departmentid=" + treenodeParent.Value.ToString(); this.TreeView1.Nodes.Add(treenodeParent); //添加子节点 for (int j = 0; j < productsLen; j++) { if (dtCategories.Rows { TreeNode treenodeChild = new TreeNode(); treenodeChild.Text = dtProductsCount.Rows[j]["departmentname"].ToString(); treenodeChild.Value = dtProductsCount.Rows[j]["departmentid"].ToString(); treenodeChild.NavigateUrl = "Paren.aspx?departmentid=" + treenodeParent.Value.ToString() + "&parentid=" + treenodeChild.Value.ToString(); treenodeParent.ChildNodes.Add(treenodeChild); } } } //TreeNode treenodeParent2 = new TreeNode(); //treenodeParent2.ImageUrl = "~/images/A1.gif"; //treenodeParent2.NavigateUrl = "BuMen.aspx"; //treenodeParent2.Text = "部门管理"; //this.TreeView1.Nodes.Add(treenodeParent2); } /// <summary> /// 节点展开 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void TreeView1_TreeNodeExpanded(object sender, TreeNodeEventArgs e) { foreach (TreeNode treenode in this.TreeView1.Nodes) { if (treenode.Value != e.Node.Value) { treenode.CollapseAll(); } } } |