数据库取值形成xml实现tree

Createthree.aspxfilesTreeViewDataSet.aspxTreeVi数据库
强烈推介IDEA2020.2破解激活,IntelliJ IDEA 注册码,2020.2 IDEA 激活码

Create three .aspx files

TreeViewDataSet.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>

本文来源21aspnet,经授权后由javajgs_com发布,观点不代表Java架构师必看的立场,转载请联系原作者。

发表评论