首页 > 编程 > .NET > 正文

Asp.net 2.0 Treeview 无限级无刷新示例

2024-07-10 13:06:40
字体:
来源:转载
供稿:网友

<%@ page language="c#" %>
<%@ import namespace="system.io" %>

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

<script runat="server">

    void treeview1_treenodepopulate(object sender, treenodeeventargs e)
    {
       if (iscallback)
            if (e.node.childnodes.count == 0)
            {
                loadchildnode(e.node);
            }
      
    }

    private void loadchildnode(treenode node)
    {
       
        directoryinfo directory;
        directory = new directoryinfo(node.value);     

        foreach (directoryinfo sub in directory.getdirectories())
        {
        
            treenode subnode = new treenode(sub.name);
            subnode.value = sub.fullname;

            try
            {
                if (sub.getdirectories().length > 0 || sub.getfiles().length > 0)
                {
                    subnode.selectaction = treenodeselectaction.selectexpand;
                    subnode.populateondemand = true;
                    subnode.navigateurl = "#";
                }
           }
            catch { subnode.imageurl = "webresource.axd?a=s&r=treeview_xp_explorer_parentnode.gif&t=632242003305625000"; }
            node.childnodes.add(subnode);
           
        }

        foreach (fileinfo fi in directory.getfiles())
        {
            treenode subnode = new treenode(fi.name);
            node.childnodes.add(subnode);
        }
    }
   
   
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>untitled page</title>
</head>

<body bgcolor="white">
    <form id="form1" runat="server">
    <div>
    <asp:treeview id="treeview1" runat="server" imageset="xpfileexplorer" autogeneratedatabindings="false" expanddepth=0
        ontreenodepopulate="treeview1_treenodepopulate"
    >
        <selectednodestyle backcolor="#b5b5b5"></selectednodestyle>
        <nodes>
            <asp:treenode value="c:" text="c:" populateondemand="true" selectaction="select" navigateurl="#" >
            </asp:treenode>
        </nodes>
        <nodestyle verticalpadding="2" font-names="tahoma" font-size="8pt" horizontalpadding="2"
            forecolor="black"></nodestyle>
        <hovernodestyle font-underline="true" forecolor="#6666aa"></hovernodestyle>
    </asp:treeview>
    </div>
    </form>
</body>
</html>

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