日期:2014-05-18  浏览次数:20489 次

关于treeview 树形结构
Protected   Sub   Page_Load(ByVal   sender   As   Object,   ByVal   e   As   System.EventArgs)   Handles   Me.Load
                Dim   ds   As   New   Data.DataSet()
                Dim   CN   As   New   SqlConnection()
                Try
                        '初始化连接字符串
                        CN.ConnectionString   =   "data   source=xie;initial   catalog=scm2;persist   security   info=False;user   id=sa;Password=; "
                        CN.Open()
                        Dim   adp   As   SqlDataAdapter   =   New   SqlDataAdapter( "select   *   from   tbTree ",   CN)
                        adp.Fill(ds)
                        Me.ViewState( "ds ")   =   ds
                Catch   ex   As   Exception
#If   DEBUG   Then
                        Session( "Error ")   =   ex.ToString()
                        Response.Redirect( "error.aspx ")                 '̀跳转程序的公共错误处理页面
#End   If
                Finally
                        '关闭连接
                        CN.Close()
                End   Try
                '调用递归函数,完成树形结构的生成
                AddTree(0,   Nothing)
        End   Sub

'递归添加树的节点
        Private   Sub   AddTree(ByVal   ParentID   As   Integer,   ByVal   pNode   As   TreeNode)
                Dim   ds   As   Data.DataSet
                ds   =   Me.ViewState( "ds ")
                Dim   dvTree   As   New   Data.DataView()
                dvTree   =   New   Data.DataView(ds.Tables(0))
                '过滤ParentID,得到当前的所有子节点
                dvTree.RowFilter   =   "PARENTID   =   "   +   ParentID.ToString

                Dim   Row   As   Data.DataRowView
                For   Each   Row   In   dvTr