ASP.NET 2005 Treeview終極解決方案
更新時間:2006年09月28日 00:00:00 作者:
這幾天在寫HRM的時候 這問題搞了我兩天,開始在使用Google 找了半天都是一堆垃圾,都是使用算法的較多, 后來就去了的msdn.yesky.com 找到點啟示。 好了廢話多說無用。
首先表結(jié)構(gòu)如下 表名 Test
寫個存儲過程 GetTreeview
這個不用我說了吧下面用到
為了速度緩存DataTable
至于速度我沒測試,如果大家有興趣幫忙測測。
首先表結(jié)構(gòu)如下 表名 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
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
至于速度我沒測試,如果大家有興趣幫忙測測。
相關(guān)文章
iis中為每個應(yīng)用程序池單獨設(shè)置aspnet.config配置文件
ASP.NET2.0之后的版本就在各Framework的根目錄下提供了一個aspnet.config文件,這個文件用來配置全局的一些信息,但是一直以來我們都沒有怎么用過2011-12-12解析GridView自帶分頁及與DropDownList結(jié)合使用
本文主要介紹了GridView自帶的分頁功能的實現(xiàn)方法。具有一定的參考價值,需要的朋友一起來看下吧2016-12-12Visual?Studio?2022常見的報錯以及處理方案圖文詳解
許多用戶在使用Visual Studio的過程中常會遇到各種問題,下面這篇文章主要給大家介紹了關(guān)于Visual?Studio?2022常見的報錯以及處理方案的相關(guān)資料,文中通過圖文介紹的非常詳細,需要的朋友可以參考下2023-04-04asp.net SAF 中緩存服務(wù)的實現(xiàn)
對緩存的興趣源于張子陽寫的一篇文章《SAF 中緩存服務(wù)的實現(xiàn)》中的一個例子:2008-08-08MVC使用T4模板生成其他類的具體實現(xiàn)學(xué)習筆記2
這篇文章主要為大家詳細介紹了MVC使用T4模板生成其他類的具體實現(xiàn),具有一定的參考價值,感興趣的小伙伴們可以參考一下2016-09-09.Net?Core和RabbitMQ限制循環(huán)消費的方法
當消費者端接收消息處理業(yè)務(wù)時,如果出現(xiàn)異常或是拒收消息將消息又變更為等待投遞再次推送給消費者,這樣一來,則形成循環(huán)的條件,這篇文章主要介紹了.Net?Core和RabbitMQ限制循環(huán)消費的方法,需要的朋友可以參考下2022-10-10