这几天在写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() 这里是主要阿 Public Sub PopulateNodes(ByVal nodes As TreeNodeCollection, Optional ByVal intParentID As Int32 = 0) Dim dt As New DataTable() 建立WebForm 放入Treeview Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load 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) |
至于速度我没测试,如果大家有兴趣帮忙测测。