1.html代码
.NET2.0 TreeView _休闲<html xmlns="http://www.w3.org/1999/xhtml" >
.NET2.0 TreeView _休闲
<head runat="server">
.NET2.0 TreeView _休闲    
<title>Untitled Page</title>
.NET2.0 TreeView _职场_04    
<script language="javascript">
.NET2.0 TreeView _职场_07        
function chkAll()
.NET2.0 TreeView _休闲_08        
{
.NET2.0 TreeView _职场_07            
//debugger;
.NET2.0 TreeView _职场_07
            var chkall= document.all["chkall"];
.NET2.0 TreeView _职场_07            
var chkother= document.getElementsByTagName("input");
.NET2.0 TreeView _职场_07            
for (var i=0;i<chkother.length;i++)
.NET2.0 TreeView _休闲_15            
{
.NET2.0 TreeView _职场_07                
if( chkother[i].type=='checkbox')
.NET2.0 TreeView _职场_19                
{
.NET2.0 TreeView _职场_07                    
if(chkother[i].id.indexOf('TreeView1')>-1)
.NET2.0 TreeView _职场_23                    
{
.NET2.0 TreeView _职场_07                        
if(chkall.checked==true)
.NET2.0 TreeView _休闲_27                        
{
.NET2.0 TreeView _职场_07                            chkother[i].checked
=false;
.NET2.0 TreeView _休闲_31                        }

.NET2.0 TreeView _职场_07                        
else
.NET2.0 TreeView _职场_33                        
{
.NET2.0 TreeView _职场_07                            chkother[i].checked
=true;
.NET2.0 TreeView _休闲_31                        }

.NET2.0 TreeView _休闲_31                    }

.NET2.0 TreeView _休闲_31                }

.NET2.0 TreeView _休闲_31            }

.NET2.0 TreeView _休闲_31        }

.NET2.0 TreeView _职场_42    
</script>
.NET2.0 TreeView _休闲
</head>
.NET2.0 TreeView _休闲
<body>
.NET2.0 TreeView _休闲    
<form id="form1" runat="server">
.NET2.0 TreeView _休闲         
<table width=100% height=100%>
.NET2.0 TreeView _休闲            
<tr height=10>
.NET2.0 TreeView _休闲                
<td><input id="chkall" type="checkbox" onclick="chkAll();" />全选/取消</td>
.NET2.0 TreeView _休闲                
<td><asp:Button ID="Button1" runat="server" Text="Button" /></td>
.NET2.0 TreeView _休闲            
</tr>
.NET2.0 TreeView _休闲            
<tr valign=top>
.NET2.0 TreeView _休闲                
<td><asp:TreeView ID="TreeView1" runat="server" ></asp:TreeView></td>
.NET2.0 TreeView _休闲                
<td><iframe id=fMain style="BORDER-TOP-STYLE: none; BORDER-RIGHT-STYLE: none; BORDER-LEFT-STYLE: none; BORDER-BOTTOM-STYLE: none"
.NET2.0 TreeView _休闲                            src
="" frameBorder="0" width="100%" scrolling="yes" height="100%"></iframe></td>
.NET2.0 TreeView _休闲            
</tr>
.NET2.0 TreeView _休闲            
<tr height=10>
.NET2.0 TreeView _休闲                
<td></td>
.NET2.0 TreeView _休闲            
</tr>
.NET2.0 TreeView _休闲        
</table>
.NET2.0 TreeView _休闲
.NET2.0 TreeView _休闲    
</form>
.NET2.0 TreeView _休闲
</body>
.NET2.0 TreeView _休闲
</html>
.NET2.0 TreeView _休闲
2.cs代码
.NET2.0 TreeView _休闲using System;
.NET2.0 TreeView _休闲
using System.Data;
.NET2.0 TreeView _休闲
using System.Configuration;
.NET2.0 TreeView _休闲
using System.Collections;
.NET2.0 TreeView _休闲
using System.Web;
.NET2.0 TreeView _休闲
using System.Web.Security;
.NET2.0 TreeView _休闲
using System.Web.UI;
.NET2.0 TreeView _休闲
using System.Web.UI.WebControls;
.NET2.0 TreeView _休闲
using System.Web.UI.WebControls.WebParts;
.NET2.0 TreeView _休闲
using System.Web.UI.HtmlControls;
.NET2.0 TreeView _休闲
using System.Data.SqlClient;
.NET2.0 TreeView _休闲
.NET2.0 TreeView _休闲
public partial class Page_Wonderful_TreeView_System.Web.UI.Page
.NET2.0 TreeView _职场_78
{
.NET2.0 TreeView _职场_07    
protected void Page_Load(object sender, EventArgs e)
.NET2.0 TreeView _休闲_82    
{
.NET2.0 TreeView _职场_07        
if (!Page.IsPostBack)
.NET2.0 TreeView _休闲_86        
{
.NET2.0 TreeView _职场_07            
//BindTree();
.NET2.0 TreeView _职场_07
            InitTree();
.NET2.0 TreeView _休闲_31        }

.NET2.0 TreeView _休闲_31    }

.NET2.0 TreeView _职场_07
.NET2.0 TreeView _职场_95    
#region 主从表绑定
.NET2.0 TreeView _职场_07    
private void BindTree()
.NET2.0 TreeView _职场_97    
{
.NET2.0 TreeView _职场_07        DataSet dst 
= GetTreeViewData();
.NET2.0 TreeView _职场_07        TreeView1.ShowCheckBoxes 
= TreeNodeTypes.All;
.NET2.0 TreeView _职场_07        
foreach (DataRow masterRow in dst.Tables["province"].Rows)
.NET2.0 TreeView _职场_103        
{
.NET2.0 TreeView _职场_07            TreeNode masterNode 
= new TreeNode((string)masterRow["province"]);
.NET2.0 TreeView _职场_07            TreeView1.Nodes.Add(masterNode);
.NET2.0 TreeView _职场_07            
foreach (DataRow childRow in masterRow.GetChildRows("Children"))
.NET2.0 TreeView _休闲_109            
{
.NET2.0 TreeView _职场_07                TreeNode childNode 
=new TreeNode((string)childRow["city"]);
.NET2.0 TreeView _职场_07                masterNode.Expanded 
= false;
.NET2.0 TreeView _职场_07                masterNode.ChildNodes.Add(childNode);
.NET2.0 TreeView _休闲_31            }

.NET2.0 TreeView _休闲_31        }

.NET2.0 TreeView _休闲_31    }

.NET2.0 TreeView _职场_07
.NET2.0 TreeView _职场_07    
private DataSet GetTreeViewData()
.NET2.0 TreeView _休闲_120    
{
.NET2.0 TreeView _职场_07        
string constring = System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"];
.NET2.0 TreeView _职场_07        SqlConnection con 
= new SqlConnection(constring);
.NET2.0 TreeView _职场_07        SqlDataAdapter daprovince 
= new SqlDataAdapter("SELECT * FROM province", con);
.NET2.0 TreeView _职场_07        SqlDataAdapter dacity 
= new SqlDataAdapter("SELECT * FROM city", con);
.NET2.0 TreeView _职场_07        DataSet ds 
= new DataSet();
.NET2.0 TreeView _职场_07        daprovince.Fill(ds, 
"province");
.NET2.0 TreeView _职场_07        dacity.Fill(ds, 
"city");
.NET2.0 TreeView _职场_07        ds.Relations.Add(
"Children", ds.Tables["province"].Columns["provinceid"], ds.Tables["city"].Columns["father"]);
.NET2.0 TreeView _职场_07        
return ds;
.NET2.0 TreeView _休闲_31    }

.NET2.0 TreeView _休闲_31    
#endregion

.NET2.0 TreeView _职场_07
.NET2.0 TreeView _职场_136    
#region 递归绑定同一个表数据
.NET2.0 TreeView _职场_07    
private void InitTree()
.NET2.0 TreeView _休闲_138    
{
.NET2.0 TreeView _职场_07        DataTable dt 
= GetTreeViewTable();
.NET2.0 TreeView _职场_07        DataView dv 
= new DataView(dt);
.NET2.0 TreeView _职场_07        dv.RowFilter 
= "ParentID=0";
.NET2.0 TreeView _职场_07        TreeView1.ShowCheckBoxes 
= TreeNodeTypes.All;
.NET2.0 TreeView _职场_07        
foreach (DataRowView drv in dv)
.NET2.0 TreeView _职场_146        
{
.NET2.0 TreeView _职场_07            TreeNode node 
= new TreeNode();
.NET2.0 TreeView _职场_07            node.Text 
= drv["text"].ToString();
.NET2.0 TreeView _职场_07            node.Value 
= drv["ID"].ToString();
.NET2.0 TreeView _职场_07            node.Expanded 
= false;
.NET2.0 TreeView _职场_07            TreeView1.Nodes.Add(node);
.NET2.0 TreeView _职场_07            AddReplies(dt,node);
.NET2.0 TreeView _休闲_31        }

.NET2.0 TreeView _休闲_31    }

.NET2.0 TreeView _职场_07
.NET2.0 TreeView _职场_07    
private DataTable GetTreeViewTable()
.NET2.0 TreeView _职场_159    
{
.NET2.0 TreeView _职场_07        
string constring = System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"];
.NET2.0 TreeView _职场_07        SqlConnection con 
= new SqlConnection(constring);
.NET2.0 TreeView _职场_07        SqlDataAdapter da 
= new SqlDataAdapter("SELECT * FROM treeview", con);
.NET2.0 TreeView _职场_07        DataTable dt 
= new DataTable();
.NET2.0 TreeView _职场_07        da.Fill(dt);
.NET2.0 TreeView _职场_07        
return dt;
.NET2.0 TreeView _休闲_31    }

.NET2.0 TreeView _职场_07
.NET2.0 TreeView _职场_07    
private void AddReplies(DataTable dt, TreeNode node)
.NET2.0 TreeView _休闲_171    
{
.NET2.0 TreeView _职场_07        DataView dv 
= new DataView(dt);
.NET2.0 TreeView _职场_07        dv.RowFilter 
= "ParentID='" + node.Value + "'";
.NET2.0 TreeView _职场_07        
foreach (DataRowView row in dv)
.NET2.0 TreeView _休闲_177        
{
.NET2.0 TreeView _职场_07            TreeNode replyNode 
= new TreeNode();
.NET2.0 TreeView _职场_07            replyNode.Text 
= row["text"].ToString();
.NET2.0 TreeView _职场_07            replyNode.Value 
= row["ID"].ToString();
.NET2.0 TreeView _职场_07            replyNode.Expanded 
= false;
.NET2.0 TreeView _职场_07            node.ChildNodes.Add(replyNode);
.NET2.0 TreeView _职场_07            AddReplies(dt,replyNode);
.NET2.0 TreeView _休闲_31        }

.NET2.0 TreeView _休闲_31    }

.NET2.0 TreeView _休闲_31    
#endregion

.NET2.0 TreeView _职场_42}