首页 > 编程 > .NET > 正文

asp.net 2.0 中递归树的实现

2024-07-10 13:06:08
字体:
来源:转载
供稿:网友
  • 网站运营seo文章大全
  • 提供全面的站长运营经验及seo技术!
  • html页面:

     

    --------------------------------------------------------------------------------


    <%[email protected] page language="vb" autoeventwireup="false" codefile="treeview.aspx.vb" inherits="treeview" %>

    <!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>无标题页</title>
        <base target="main">
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <asp:treeview id="treeview1" runat="server" expanddepth="1" font-size="9pt" autogeneratedatabindings="false" enabletheming="true" nodewrap="true" showlines="true" target="_blank">
            </asp:treeview>
       
        </div>
        </form>
    </body>
    </html>
     后台cs代码:

     

    --------------------------------------------------------------------------------


    imports system.web
    imports system.data.sqlclient
    imports system.data

    partial class treeviewclass treeview
        inherits system.web.ui.page

        dim ds as dataset = new system.data.dataset()


        protected sub page_load()sub page_load(byval sender as object, byval e as system.eventargs) handles me.load
            if not ispostback then
                dim sqlstr as string = "select a.*,t32003.t3200303 as orderprogramid from(select 项目代码 as nodeid,项目名称 as nodename,项目名称 as parentid from acf_v_lefttree_admin where 项目代码<>' ' and 项目代码 is not null group by 项目代码,项目名称 union all select 系统代码 as nodeid,系统名称 as nodename,项目代码 as parentid from acf_v_lefttree_admin where 系统代码<>' ' and 系统代码 is not null group by 项目代码,系统代码,系统名称  union all select 子系统代码 as nodeid,子系统名称 as nodename,系统代码 as parentid from acf_v_lefttree_admin where 子系统代码<>' ' and 子系统代码 is not null group by 系统代码,子系统代码,子系统名称  union all select 程式代码 as nodeid,程式名称 as nodename,子系统代码 as parentid from acf_v_lefttree_admin where  程式代码<>' ' and 程式代码 is not null group by 子系统代码,程式代码,程式名称 ) a left outer join t32003 on a.nodeid = t32003.t3200301"
                dim conn as sqlconnection = new sqlconnection("server=(local);database=acfv3;uid=sa;pwd=888888")
                dim sqlada as sqldataadapter = new sqldataadapter(sqlstr, conn)
                sqlada.fill(ds, "treetb")
                createtree(treeview1.nodes, "我的acf")

            end if
        end sub

        private sub createtree()sub createtree(byval treevwnds as treenodecollection, byval strcurrentid as string)
            dim datviw as new dataview
            dim datrow as datarowview
            dim treevwnode as treenode
            dim currentid as string
            datviw.table = ds.tables("treetb")
            datviw.sort = "orderprogramid"
            try
                datviw.rowfilter = " parentid ='" & strcurrentid & "'"
                if datviw.count > 0 then
                    for each datrow in datviw
                        treevwnode = new treenode
                        treevwnode.value = datrow("nodeid")
                        currentid = datrow("nodeid")
                        treevwnds.add(treevwnode)
                        treevwnode.text = trim(datrow("nodename"))
                        treevwnode.target = "_blank"
                        dim i as integer = treevwnds.count
                        createtree(treevwnds(treevwnds.count - 1).childnodes, currentid)
                    next
                end if
            catch ex as exception
                response.write(ex.tostring)

            end try

        end sub
    end class

    发表评论 共有条评论
    用户名: 密码:
    验证码: 匿名发表