Create three .aspx filesTreeViewDataSet.aspx<%@ import Namespace="Microsoft.Web.UI.WebControls" %> <%@ Register TagPrefix="IE" Namespace="Microsoft.Web.UI.WebControls" Assembly="Microsoft.Web.UI.WebControls" %><html> <head> <title> TreeViewDataSet.aspx </title> </head> <body> <form runat="Server"> <IE:TreeView AutoPostBack="True" TreeNodeSrc="Categories.aspx" Runat="Server"/> </form> </body> </html>Categories.aspx <%@ Import Namespace="System.Data" %> <%@ Import Namespace="System.Data.SqlClient" %><Script runat="Server"> sub page_load Dim mycon as SqlConnection Dim cmdCategories As SqlCommand Dim dsCategories As DataSet Dim strQuery As String mycon=New Sqlconnection("Server=localhost;UID=sa;PWD=secret;Database=Northwind") strQuery="select categoryname as Text,'products.aspx?catid=' +LTRIM(STR(CategoryID))" & _ "As TreeNodeSrc from Categories As TreeNode for xml auto, XMLDATA" cmdCategories=new SqlCommand(strQuery,mycon) dsCategories=New DataSet dsCategories.ReadXML(cmdCategories.ExecuteXmlReader(),XmlReadMode.Fragment) dsCategories.DataSetName="TREENODES" dsCategories.WriteXml(Response.OutputStream) end sub </script>Products.aspx <%@ Import Namespace="System.Data" %> <%@ Import Namespace="System.Data.SqlClient" %><Script runat="Server"> sub page_load Dim mycon as SqlConnection Dim cmdProducts As SqlCommand Dim dsProducts As DataSet Dim strQuery As String mycon=New Sqlconnection("Server=localhost;UID=sa;PWD=secret;Database=Northwind") strQuery="select Productname as Text from products As TreeNode" & _ " where CategoryID=@categoryID for xml auto, XMLDATA " cmdproducts=new SqlCommand(strQuery,mycon) cmdproducts.Parameters.Add(New SqlParameter("@categoryID",Request.QueryString("catID"))) mycon.open() dsproducts=New DataSet dsproducts.ReadXML(cmdproducts.ExecuteXmlReader(),XmlReadMode.Fragment) dsproducts.DataSetName="TREENODES" dsproducts.WriteXml(Response.OutputStream) mycon.close() end sub </script>
http://www.gotdotnet.com/team/webcontrols/treeview/tree_db_xml_1.aspx
<%@ Register TagPrefix="IE" Namespace="Microsoft.Web.UI.WebControls" Assembly="Microsoft.Web.UI.WebControls" %><html>
<head>
<title>
TreeViewDataSet.aspx
</title>
</head>
<body>
<form runat="Server">
<IE:TreeView
AutoPostBack="True"
TreeNodeSrc="Categories.aspx"
Runat="Server"/>
</form>
</body>
</html>Categories.aspx
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %><Script runat="Server">
sub page_load
Dim mycon as SqlConnection
Dim cmdCategories As SqlCommand
Dim dsCategories As DataSet
Dim strQuery As String mycon=New Sqlconnection("Server=localhost;UID=sa;PWD=secret;Database=Northwind")
strQuery="select categoryname as Text,'products.aspx?catid='
+LTRIM(STR(CategoryID))" & _
"As TreeNodeSrc from Categories As TreeNode for xml auto, XMLDATA"
cmdCategories=new SqlCommand(strQuery,mycon)
dsCategories=New DataSet
dsCategories.ReadXML(cmdCategories.ExecuteXmlReader(),XmlReadMode.Fragment)
dsCategories.DataSetName="TREENODES"
dsCategories.WriteXml(Response.OutputStream)
end sub
</script>Products.aspx
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %><Script runat="Server">
sub page_load
Dim mycon as SqlConnection
Dim cmdProducts As SqlCommand
Dim dsProducts As DataSet
Dim strQuery As String mycon=New Sqlconnection("Server=localhost;UID=sa;PWD=secret;Database=Northwind")
strQuery="select Productname as Text from products As TreeNode" & _
" where CategoryID=@categoryID for xml auto, XMLDATA "
cmdproducts=new SqlCommand(strQuery,mycon)
cmdproducts.Parameters.Add(New SqlParameter("@categoryID",Request.QueryString("catID")))
mycon.open()
dsproducts=New DataSet
dsproducts.ReadXML(cmdproducts.ExecuteXmlReader(),XmlReadMode.Fragment)
dsproducts.DataSetName="TREENODES"
dsproducts.WriteXml(Response.OutputStream)
mycon.close()
end sub
</script>
http://www.gotdotnet.com/team/webcontrols/treeview/tree.aspx
从google搜索出来的
不能连续回复一个帖子3次 只能现在才贴了
<HTML>
<HEAD>
<title>treeTemp</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form name="Form1" method="post" action="treeTemp.aspx" id="Form1">
<input type="hidden" name="__TreeView1_State__" value="" />
<input type="hidden" name="__VIEWSTATE" value="dDwtMTc0NjQ0NjIxNDt0PDtsPGk8MT47PjtsPHQ8O2w8aTwxPjs+O2w8dDxAMDxwPHA8bDxTZWxlY3RlZE5vZGVJbmRleDs+O2w8MDs+Pjs+Ozs7OztAMDw7QDA8bDxpPDA+Oz47bDxAMDxAMDxwPGw8U2VsZWN0ZWQ7PjtsPG88dD47Pj47Ozs7Pjs7Pjs+Oz47Pjs+Ozs+Oz4+Oz4+O2w8VHJlZVZpZXcxOz4+Zsw45pS5RzO6kaVf7jITwEPRZnw=" /> <FONT face="宋体">
<?XML:NAMESPACE PREFIX=TVNS />
<?IMPORT NAMESPACE=TVNS IMPLEMENTATION="/webctrl_client/1_0/treeview.htc" />
<tvns:treeview id="TreeView1" imageUrl="webctrl_client/1_0/treeimages/Rplus.gif" expandedImageUrl="webctrl_client/1_0/treeimages/Rminus.gif" selectedNodeIndex="0" HelperID="__TreeView1_State__" systemImagesPath="/webctrl_client/1_0/treeimages/" onexpand="javascript: if (this.clickedNodeIndex != null) this.queueEvent('onexpand', this.clickedNodeIndex)" oncollapse="javascript: if (this.clickedNodeIndex != null) this.queueEvent('oncollapse', this.clickedNodeIndex)" oncheck="javascript: if (this.clickedNodeIndex != null) this.queueEvent('oncheck', this.clickedNodeIndex)" onselectedindexchange="javascript: if (event.oldTreeNodeIndex != event.newTreeNodeIndex) this.queueEvent('onselectedindexchange', event.oldTreeNodeIndex + ',' + event.newTreeNodeIndex)" style="Z-INDEX: 101; LEFT: 8px; POSITION: absolute; TOP: 8px">
<tvns:treenode Selected="true">
根目录<tvns:treenode>
系统管理<tvns:treenode NavigateUrl="http://www.humen.com">
系统管理1
</tvns:treenode><tvns:treenode>
系统管理2
</tvns:treenode>
</tvns:treenode><tvns:treenode>
新闻管理
</tvns:treenode>
</tvns:treenode>
</tvns:treeview></FONT>
</form>
</body>
</HTML>