Implementation of recursive tree in asp.net 2.0

Source: Internet
Author: User
asp.net| recursion

HTML page:

--------------------------------------------------------------------------------


<%...@ Page language= "VB" autoeventwireup= "false" codefile= "TreeView.aspx.vb" inherits= "TreeView"%>

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">

<title> Untitled Page </title>
<base target= "Main" >

<body>
<form id= "Form1" runat= "Server" >
<div>
<asp:treeview id= "TreeView1" runat= "Server" expanddepth= "1" font-size= "9pt" autogeneratedatabindings= "False" Enabletheming= "true" nodewrap= "true" showlines= "true" target= "_blank" >
</asp:TreeView>

</div>
</form>
</body>

Background CS Code:

--------------------------------------------------------------------------------


Imports system.web
Imports System.Data.SqlClient
Imports System.Data

Partial Class Treeviewclass TreeView
Inherits System.Web.UI.Page

Dim ds as DataSet = New System.Data.DataSet ()


Protected Sub Page_Load () Sub Page_Load (ByVal sender as Object, ByVal e as System.EventArgs) Handles Me.load
If not IsPostBack Then
Dim sqlstr as String = "Select A.*,t32003." T3200303 as Orderprogramid from (select Project Code as NodeID, project name as NodeName, project name as ParentID from Acf_v_lefttree_admin where project Code <> ' and project code is not NULL group by project code, project name UNION ALL select system code as NodeID, system name as NodeName, Project code as ParentID FR Om acf_v_lefttree_admin where system code <> ' NOT NULL group by project code, system code, System name UNION ALL select subsystem Code as node ID, subsystem name as NodeName, system code as ParentID from Acf_v_lefttree_admin where subsystem code <> ' and subsystem code is NOT NULL group by system code , subsystem code, subsystem name UNION ALL select Code as NodeID, program name as NodeName, subsystem code as parentid from Acf_v_lefttree_admin where code < > ' and program code is isn't null group by subsystem Code, code, program name] a left outer join T32003 on a.nodeid = T32003. T3200301 "
Dim conn As SqlConnection = New SqlConnection ("server= (local);d atabase=acfv3;uid=sa;pwd=888888")
Dim Sqlada As SqlDataAdapter = New SqlDataAdapter (SQLSTR, conn)
Sqlada. Fill (ds, "Treetb")
Createtree (Treeview1.nodes, "my ACF")

End If
End Sub

Private Sub Createtree () Sub Createtree (ByVal treevwnds as TreeNodeCollection, ByVal Strcurrentid as String)
Dim Datviw as New DataView
Dim Datrow as DataRowView
Dim Treevwnode as TreeNode
Dim CurrentID as String
Datviw. Table = ds. Tables ("Treetb")
Datviw. Sort = "Orderprogramid"
Try
Datviw. RowFilter = "ParentID = '" & Strcurrentid & "'"
If Datviw. Count > 0 Then
For each datrow in DATVIW
Treevwnode = New TreeNode
Treevwnode.value = Datrow ("NodeID")
CurrentID = Datrow ("NodeID")
Treevwnds.add (Treevwnode)
Treevwnode.text = Trim (Datrow ("NodeName"))
Treevwnode.target = "_blank"
Dim i as Integer = Treevwnds.count
Createtree (Treevwnds (treevwnds.count-1). ChildNodes, CurrentID)
Next
End If
Catch ex as Exception
Response.Write (ex. ToString)

End Try

End Sub
End Class



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.