欢迎光临
我们一直在努力

ASP.net 2005 Treeview 无限分类非地递归终极解决方案-.NET教程,Asp.Net开发

建站超值云服务器,限时71元/月

这几天在写hrm的时候 这问题搞了我两天,哈哈!开始在使用google 找了半天都是一堆垃圾,都是使用算法的较多, 后来就去了www.asp.net 找到点启示。

好了废话多说无用。

首先表结构如下 表名 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

至于速度我没测试,如果大家有兴趣帮忙测测。

 

题外话(突然发现自己老了,26岁了写了快7年的程序了 一直使用vb各种版本,   masmms宏汇编语言)在vb 6.0 时代 2000 年左右建立了 vb 编程为主的个人主页编程浪子) by shadow

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » ASP.net 2005 Treeview 无限分类非地递归终极解决方案-.NET教程,Asp.Net开发
分享到: 更多 (0)