网页教学网
 当前位置: 网页教学网 >> 网络编程 >> PHP编程技术 >> 阅读:.NET Treeview无限级无刷新示例
[ HTML ] [ FW ] [ DW ] [ FP ] [ JS ] [ XML ] [ CSS ] [ 图象 ] [ FLASH ] [ .NET ] [ ASP ] [ JSP ] [ PHP ] [ 数据 ] [ 系统 ] [ 安全 ] [ 素材 ] [ 建站 ] [ 主机 ] [ 入门 ] [ 技巧 ]

.NET Treeview无限级无刷新示例

http://www.webjx.com  更新日期:2007-03-02 21:52  出处:CSDN  作者: 收藏本文

<%@ 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>

关键词:
推荐给好友】【关闭
最新五条评论
查看全部评论
评论总数 0
您的评论
用户名: 新注册) 密 码: 匿名:
·用户发表意见仅代表其个人意见,并且承担一切因发表内容引起的纠纷和责任
·本站管理人员有权在不通知用户的情况下删除不符合规定的评论信息或留做证据
·请客观的评价您所看到的资讯,提倡就事论事,杜绝漫骂和人身攻击等不文明行为