
ASP.NET 2005 Treeview终极解决方案
发布时间:2006-06-19 12:27:22 来源:BLOG 网友评论 0 条
这几天在写HRM的时候 这问题搞了我两天,开始在使用Google 找了半天都是一堆垃圾,都是使用算法的较多, 后来就去了的msdn.yesky.com 找到点启示。 好了废话多说无用。
首先表结构如下 表名 Test
写个存储过程 GetTreeview
这个不用我说了吧下面用到
为了速度缓存DataTable
至于速度我没测试,如果大家有兴趣帮忙测测。
首先表结构如下 表名 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 |
至于速度我没测试,如果大家有兴趣帮忙测测。
推荐阅讯
- .NET正则表达式使用高级技巧之反向引用
- 10天学会ASP.net之第八天
- ASP.NET2.0服务器控件之类型转换器
- ASP.NET2.0实现无刷新客户端回调
- ASP.Net的Session
- ASP.NET 2.0移动开发入门之基础
- 在ASP.NET 2.0中实现本地化
- ASP.NET 2.0轻松实现数据库应用开发
- ASP.NET+AJAX解决网页打开等待问题
- ASP.NET2.0数据库入门之SQL Server
阅读排行
- 1.用ASP.NET 2.0设计网络在线投票系统
- 2.在ASP.Net 2.0中实现多语言界面的方法
- 3.轻松加密ASP.NET 2.0 Web程序配置信息
- 4.在ASP.NET中使用AJAX的简单方法
- 5..NET 2.0中的企业库异常处理块简述
- 6.面向.NET开发人员的Ajax 技术平台策略
- 7.揭开ASP.NET中Cookie编程的奥秘
- 8.ASP.NET2.0服务器控件之创建自定义控件
- 9.ASP.NET2.0中Gridview中数据操作技巧
- 10.ASP.NET 2.0发送电子邮件全面剖析之二
专题教程
- 大话G游 专题:手机病毒揭密
- ARP攻击防范与解决方案 路由故障处理手册
- Picasa中文版_Picasa教程 专题:清除流氓软件
- Firefox专题 seo搜索引擎优化专区
- 重装Windows必知的事情 装机之必备软件大行动
病毒专杀栏

