asp.net 2.0 中遞迴樹的實現

來源:互聯網
上載者:User
asp.net|遞迴

HTML頁面:

 

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


<%...@ 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">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>無標題頁</title>
    <BASE target="main">
</head>
<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>
</html>
 後台CS代碼:

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


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"
        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



相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

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

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.