这几天在写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
至于速度我没测试,如果大家有兴趣帮忙测测。
首先表结构如下 表名 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
至于速度我没测试,如果大家有兴趣帮忙测测。
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件!
如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
桃源资源网 Design By www.nqtax.com
暂无“ASP.NET 2005 Treeview终极解决方案”评论...
RTX 5090要首发 性能要翻倍!三星展示GDDR7显存
三星在GTC上展示了专为下一代游戏GPU设计的GDDR7内存。
首次推出的GDDR7内存模块密度为16GB,每个模块容量为2GB。其速度预设为32 Gbps(PAM3),但也可以降至28 Gbps,以提高产量和初始阶段的整体性能和成本效益。
据三星表示,GDDR7内存的能效将提高20%,同时工作电压仅为1.1V,低于标准的1.2V。通过采用更新的封装材料和优化的电路设计,使得在高速运行时的发热量降低,GDDR7的热阻比GDDR6降低了70%。