asp.net 2.0中treeview中动态增加结点
来源:互联网 发布:山东长川软件 编辑:程序博客网 时间:2024/05/17 02:52
主要代码如下:
- <html>
- <head>
- </head>
- <body>
- <form id="form1" runat="server">
- <div>
- <asp:TreeViewRunat="Server" ExpandImageUrl="Images/closed.gif"
- CollapseImageUrl="Images/open.gif"
- OnTreeNodePopulate="Node_Populate" ID="tvwauthors">
- <Nodes>
- <asp:TreeNodeText="Authors" PopulateOnDemand=true
- Value="0"/>
- </Nodes>
- </asp:TreeView>
- </div>
- </form>
- </body>
- </html>
后台代码:
- void Node_Populate(objectsender,System.Web.UI.WebControls.TreeNodeEventArgs e)
- {
- if(e.Node.ChildNodes.Count == 0)
- {
- switch( e.Node.Depth )
- {
- case 0:
- FillAuthors(e.Node);
- break;
- case 1:
- FillTitlesForAuthors(e.Node);
- break;
- }
- }
- }
- void FillAuthors(TreeNode node)
- {
- string connString = System.Configuration.ConfigurationSettings.
- ConnectionStrings["NorthwindConnnection"].ConnectionString;
- SqlConnection connection = new SqlConnection(connString);
- SqlCommand command = new SqlCommand("Select * From
- authors",connection);
- SqlDataAdapter adapter = new SqlDataAdapter(command);
- DataSet authors = new DataSet();
- adapter.Fill(authors);
- if (authors.Tables.Count > 0)
- {
- foreach (DataRow row in authors.Tables[0].Rows)
- {
- TreeNode newNode = new
- TreeNode(row["au_fname"].ToString() + " " +
- row["au_lname"].ToString(),
- row["au_id"].ToString());
- newNode.PopulateOnDemand = true; //是否动态填充节点
- newNode.SelectAction = TreeNodeSelectAction.Expand; //选择节点时引发的事件(切换节点的展开和折叠状态。)
- node.ChildNodes.Add(newNode);
- }
- }
- }
- void FillTitlesForAuthors(TreeNode node)
- {
- string authorID = node.Value;
- string connString = System.Configuration.ConfigurationSettings.
- ConnectionStrings["NorthwindConnnection"].ConnectionString;
- SqlConnection connection = new SqlConnection(connString);
- SqlCommand command = new SqlCommand("Select T.title,
- T.title_id From titles T" +
- " Inner Join titleauthor TA on
- T.title_id = TA.title_id " +
- " Where TA.au_id = '" + authorID + "'", connection);
- SqlDataAdapter adapter = new SqlDataAdapter(command);
- DataSet titlesForAuthors = new DataSet();
- adapter.Fill(titlesForAuthors);
- if (titlesForAuthors.Tables.Count > 0)
- {
- foreach (DataRow row in titlesForAuthors.Tables[0].Rows)
- {
- TreeNode newNode = new TreeNode(
- row["title"].ToString(), row["title_id"].ToString());
- newNode.PopulateOnDemand = false; //是否动态填充节点
- newNode.SelectAction = TreeNodeSelectAction.None;
- node.ChildNodes.Add(newNode);
- }
- }
- }
- asp.net 2.0中TREEVIEW中动态增加结点
- asp.net 2.0中TREEVIEW中动态增加结点
- asp.net 2.0中TREEVIEW中动态增加结点
- asp.net 2.0中TREEVIEW中动态增加结点
- asp.net 2.0中treeview中动态增加结点
- asp.net 2.0中TREEVIEW中动态增加结点
- asp.net 2.0中TREEVIEW中动态增加结点
- asp.net 2.0中TREEVIEW中动态增加结点
- asp.net 2.0中TREEVIEW中动态增加结点
- 1.TreeView.应用--2.asp.net 2.0中TREEVIEW中动态增加结点--3.msdn中nasp.net 2.0中TREEVIEW中动态增加结点--4.TreeView.ImageSet 属性,换换treeview的皮肤
- 1.TreeView.应用--2.asp.net 2.0中TREEVIEW中动态增加结点--3.msdn中nasp.net 2.0中TREEVIEW中动态增加结点--4.TreeView.ImageSet 属性,换换treeview的皮肤收藏
- 黑马程序员之ASP.NET学习笔记:TREEVIEW中动态增加结点
- asp.net实现TreeView控件动态增加结点代码
- net2.0中TREEVIEW中动态增加结点
- TreeView中动态增加节点(ASP.NET2.0)
- ASP.NET 2.0中TreeView递归遍历及设置结点展开算法
- Asp.net中Treeview
- asp.net中动态生成 Microsoft.Web.UI.WebControls.TreeView
- Hello China最新开发进展
- 初识AIX
- 中东乱局来龙去脉
- Linux系统下ifconfig命令结果分析
- skyeye运行uClinux
- asp.net 2.0中treeview中动态增加结点
- 全国人民代表大会常务委员会关于修改《中华人民共和国专利法》的决定[转]
- MoveWindow in MFC
- Ape格式转换Apple Lossless(m4a)格式再同步到Ipod
- 关于通过SMTP服务器群发邮件的实现——我的Web开发心得
- 存储过程编写经验和优化措施
- Unix之AIX中的存储管理
- windows下配置PHP+MySQL开发环境
- zebra使用手册