| 搜索频道 | 源码下载 | 站长代码论坛 | 文章分类 | 最新专题 | 源码交易 | 加入收藏
首页|资讯|图形图像|网站开发|程序设计|数据库|多媒体|机械电子|办公系列|路由技术|原理|应用|考试|系统
文章搜索:
 您的位置:首页网站开发ASP.NETAsp.NET开发实例 → ASP.NET 2005 Treeview终极解决方案
ASP.NET 2005 Treeview终极解决方案

日期:2006-8-10 10:01:14 人气:     [ ]
  这几天在写HRM的时候 这问题搞了我两天,开始在使用Google 找了半天都是一堆垃圾,都是使用算法的较多, 后来就去了的msdn.yesky.com 找到点启示。 好了废话多说无用。

  首先表结构如下 表名 Test


  写个存储过程 GetTreeview

  这个不用我说了吧下面用到

  为了速度缓存DataTable

Public Function GetTreeTable() As DataTable
 Dim dt As New DataTable()
 dt = HttpContext.Current.Cache("Treeview")
 If dt Is Nothing Then
  Dim Conn As New SqlConnection
  Dim clsConnDatabase As New ConnectionDatabase
  Conn = clsConnDatabase.ConnDatabase
  Dim Command As New SqlCommand
  Command.Connection = Conn
  Command.CommandText = "GetTreeview"
  Command.CommandType = CommandType.StoredProcedure
  Command.ExecuteNonQuery()

  Dim da As New SqlDataAdapter(Command)

  dt = New DataTable()
  da.Fill(dt)
  HttpContext.Current.Cache.Insert("Treeview", dt)
 End If
 Return dt
End Function

  这里是主要阿

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

 Dim dt As New DataTable()
 dt = clsWebForms.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()
  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

  建立WebForm 放入Treeview

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

  至于速度我没测试,如果大家有兴趣帮忙测测。
出处:本站原创 作者:zzcode
 相关文章
·树视TreeView树视的使用技巧
·在VB6中将XML传入一个TreeView控件
 相关软件
·ASP TreeView
 

 热点文章

·ASP.NET 2.0站点地图搭..
·在ASP.NET应用中插入f..
·ASP.NET入门随想之检票..
·ASP.NET2.0数据库入门..
·ASP.NET2.0数据库入门..
·ASP.NET 2005 Treevie..
·用ASP.NET语法创建Web..
·ASP.NET2.0服务器控件..

 推荐文章

·端午非物质文化遗产登..
·动态网站Web开发PHP、..
·PS绘中秋佳节的一轮明..
·细谈网页优化和网站优..
·建站常识:如何使用FT..
·如何快速建造一个成功..
·ASP.NET 2.0 中的创建..
·ASP.NET2.0服务器控件..
·在ASP.NET应用中插入f..
·用Photoshop打造逼真立..
·Windows 2003搭建虚拟..
·站长必读:Web创业的1..
·如何测试机房的速度和..
·北京奥运体育图标发布..
·网络视频广告将身价百..