【Vegas原创】TreeView操作数据库的使用方法(VB)

      Dim  dbAccess  As   New  DBAccess

        
Protected   Sub  Page_Load( ByVal  sender  As   Object ByVal  e  As  System.EventArgs)  Handles   Me .Load
            
If   Not  Page.IsPostBack  Then
                PopulateNodes(TreeView1.Nodes, 
0 )

            
End   If
        
End Sub

        
Protected   Sub  TreeView1_TreeNodePopulate( ByVal  sender  As   Object ByVal  e  As  System.Web.UI.WebControls.TreeNodeEventArgs)  Handles  TreeView1.TreeNodePopulate

            PopulateNodes(e.Node.ChildNodes, e.Node.Value)

        
End Sub

        
Public   Sub  PopulateNodes( ByVal  nodes  As  TreeNodeCollection,  Optional   ByVal  intParentID  As  Int32  =   0 )

            
Dim  dt  As   New  DataTable()
            dt 
=  GetTreeTable()
            
Dim  strExpression  As   String
            strExpression 
=   " [parentID] =  "   &  intParentID
            
Dim  foundRows()  As  DataRow
            foundRows 
=  dt.Select(strExpression)

            
Dim  I  As   Integer
            
For  I  =   0   To  foundRows.GetUpperBound( 0 )
                
Dim  tn  As   New  TreeNode()

                tn.Text 
=  foundRows(I).Item( " TableName " ).ToString()
                tn.Value 
=  foundRows(I).Item( " ID " ).ToString()
                tn.NavigateUrl 
=  foundRows(I).Item( " url " ).ToString()
                tn.Target 
=  foundRows(I).Item( " target " ).ToString()
                tn.CollapseAll()
                tn.Expand()

                
Dim  dr()  As  DataRow
                dr 
=  dt.Select( " [parentID] =  "   &  tn.Value)
                
If  dr.GetUpperBound( 0 >   - 1   Then
                    tn.PopulateOnDemand 
=   True
                
End   If
                nodes.Add(tn)
            
Next

          
        
End Sub

        
Public   Function  GetTreeTable()  As  DataTable
            
Dim  dt  As   New  DataTable()
            
Dim  ds  As   New  DataSet()
            
' ''''''''''''''''''''''''TreeView Visible ~~~~~~~~~~~~~~~~~~~~~~@#@!~~~ by Vegas 

            
Dim  cookies  As  HttpCookie
            cookies 
=  Request.Cookies( " PAS " )
            
Dim  workid  As   String   =  cookies( " Emp_No " )
            
Dim  strPa_Rank  As   String   =  cookies( " Job_Rank " )
            
Dim  super_user  As   String   =  cookies( " Super_User " )

            
If   Integer .Parse(strPa_Rank)  >   30   Then
                
If   Integer .Parse(super_user)  =   0   Then
                    dt 
=  dbAccess.GetDataTable( " select * from treeview where id<>2 and id<>4 order by id " )
                    HttpContext.Current.Cache.Insert(
" Treeview " , dt)
                
Else
                    dt 
=  dbAccess.GetDataTable( " select * from treeview order by id " )
                    HttpContext.Current.Cache.Insert(
" Treeview " , dt)
                
End   If
            
Else
                
If   Integer .Parse(super_user)  =   0   Then

                    dt 
=  dbAccess.GetDataTable( " select * from treeview where id<>2 order by id " )
                    HttpContext.Current.Cache.Insert(
" Treeview " , dt)
                
Else
                    dt 
=  dbAccess.GetDataTable( " select * from treeview order by id " )
                    HttpContext.Current.Cache.Insert(
" Treeview " , dt)
                
End   If
            
End   If

            
Return  dt
        
End Function

    
End Class


表结构:

idparentIDtableNameurltargetexpanded
10绩效考核系统   
21管理者设定   
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值