ASP.NET树形1
2009-04-21 20:13 观海看云 阅读(105) 评论(0) 编辑 收藏 举报 /// <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["departmentname"].ToString(); treenodeParent.Value = dtCategories.Rows["departmentid"].ToString(); treenodeParent.NavigateUrl = "Departmen.aspx?FONT-STYLE: italic">["departmentid"].ToString() == dtProductsCount.Rows[j]["parentid"].ToString()) { 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(); } } } |
作者:观海看云(个人开发历程知识库 - 博客园)
出处:http://www.cnblogs.com/zhangtao/
文章版权归本人所有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
出处:http://www.cnblogs.com/zhangtao/
文章版权归本人所有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。