引言:
最近本人做一个项目,运用到TreeView树型目录,搜索了网上很多的实例,不知道网友是不是故弄玄虚,还是故做高深,或是本人水平有限看不懂,给出的实例源码均无法实现动态的TreeView,也有网友用MzTreeView1.0 修改过类似于Csdn社区的树型菜单,本人研究了半天,仍然无法在asp.net2.0下实现。实在为难之下,我自己做了一个,为了方便初学者,现贴出全部源码及数据库建库脚本。由于时间仓促,难免有不足之处,欢迎网友提出宝贵的修改意见。谢谢
一、效果图预览:
![](https://www.cnblogs.com/images/cnblogs_com/zm235/Tree.jpg)
二、前台Aspx代码:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
<style type="text/css">
<!--
body,td,th {
font-family: 宋体;
font-size: 9pt;
}
body {
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
}
-->
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TreeView ID="TreeView1" runat="server" Width="100%" />
</div>
</form>
</body>
</html>
三、后置代码CS文件
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
TreeViewBind();
}
}
主从表绑定
}
四、数据库:
Yp_ProBigSort表
数据结构:
iProBigSort_ID(父表主键)
sProBigName(根节点名称)
iProBigSort_ID sProBigName
1 普通内科
2 普通外科
3 妇产科
Yp_ProSmallSort表
iProSmallSort_ID(子表主键)
iProBigSortID(父表主键)
sProSmallSortName(子节点名称)
iProSmallSort_ID iProBigSortID sProSmallSortName
1 1 感冒
2 1 发烧
3 2 普通外科1
4 2 普通外科2
5 3 妇产科1
6 3 妇产科2
五、调试:
代码通过调试,无错。
最近本人做一个项目,运用到TreeView树型目录,搜索了网上很多的实例,不知道网友是不是故弄玄虚,还是故做高深,或是本人水平有限看不懂,给出的实例源码均无法实现动态的TreeView,也有网友用MzTreeView1.0 修改过类似于Csdn社区的树型菜单,本人研究了半天,仍然无法在asp.net2.0下实现。实在为难之下,我自己做了一个,为了方便初学者,现贴出全部源码及数据库建库脚本。由于时间仓促,难免有不足之处,欢迎网友提出宝贵的修改意见。谢谢
一、效果图预览:
![](https://www.cnblogs.com/images/cnblogs_com/zm235/Tree.jpg)
二、前台Aspx代码:
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
三、后置代码CS文件
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
四、数据库:
Yp_ProBigSort表
数据结构:
iProBigSort_ID(父表主键)
sProBigName(根节点名称)
iProBigSort_ID sProBigName
1 普通内科
2 普通外科
3 妇产科
Yp_ProSmallSort表
iProSmallSort_ID(子表主键)
iProBigSortID(父表主键)
sProSmallSortName(子节点名称)
iProSmallSort_ID iProBigSortID sProSmallSortName
1 1 感冒
2 1 发烧
3 2 普通外科1
4 2 普通外科2
5 3 妇产科1
6 3 妇产科2
五、调试:
代码通过调试,无错。