2.0 中遞迴樹的實現





<%...@ Page Language="VB" AutoEventWireup="false" CodeFile="TreeView.aspx.vb" Inherits="TreeView" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<html xmlns="" >
<head runat="server">
    <BASE target="main">
    <form id="form1" runat="server">
        <asp:TreeView ID="TreeView1" runat="server" ExpandDepth="1" Font-Size="9pt" AutoGenerateDataBindings="False" EnableTheming="True" NodeWrap="True" ShowLines="True" Target="_blank">


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 項目代碼 as nodeID,項目名稱 as nodeName,項目名稱 as parentID from acf_v_lefttree_Admin where 項目代碼<>' ' and 項目代碼 is not null group by 項目代碼,項目名稱 union all select 系統代碼 as nodeID,系統名稱 as nodeName,項目代碼 as parentID from acf_v_lefttree_Admin where 系統代碼<>' ' and 系統代碼 is not null group by 項目代碼,系統代碼,系統名稱  union all select 子系統代碼 as nodeID,子系統名稱 as nodeName,系統代碼 as parentID from acf_v_lefttree_Admin where 子系統代碼<>' ' and 子系統代碼 is not null group by 系統代碼,子系統代碼,子系統名稱  union all select 程式代碼 as nodeID,程式名稱 as nodeName,子系統代碼 as parentID from acf_v_lefttree_Admin where  程式代碼<>' ' and 程式代碼 is not null group by 子系統代碼,程式代碼,程式名稱 ) a left outer join T32003 on a.nodeID = T32003.T3200301"
            Dim conn As SqlConnection = New SqlConnection("server=(local);database=acfv3;uid=sa;pwd=888888")
            Dim sqlada As SqlDataAdapter = New SqlDataAdapter(sqlstr, conn)
            sqlada.Fill(ds, "TreeTb")
            createtree(TreeView1.Nodes, "我的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"
            datviw.RowFilter = " parentID ='" & strCurrentID & "'"
            If datviw.Count > 0 Then
                For Each datrow In datviw
                    TreeVwNode = New TreeNode
                    TreeVwNode.Value = datrow("nodeID")
                    currentId = datrow("nodeID")
                    TreeVwNode.Text = Trim(datrow("nodeName"))
                    TreeVwNode.Target = "_blank"
                    Dim i As Integer = TreeVwNds.Count
                    createtree(TreeVwNds(TreeVwNds.Count - 1).ChildNodes, currentId)
            End If
        Catch ex As Exception

        End Try

    End Sub
End Class


E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >



如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。