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

asp.net|treeview|示例|刷新|无刷新

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

时间: 2024-10-28 09:29:50

Asp.net 2.0 Treeview 无限级无刷新示例的相关文章

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

本文给出了使用Asp.net 2.0的Treeview实现无限级无刷新的示例源代码,供大家参考! <%@ Page Language="C#" %> <%@ Import Namespace="System.IO" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dt

ASP.NET 2.0 Treeview Checkboxes - Check All - Javascript

asp.net|javascript|treeview ASP.NET 2.0 TreeView has many built-in features such as showing a checkbox for all the Tree Nodes. Node level formating, style, etc., Enabling the ShowCheckBoxes="All" property sets it to show a checkbox for all the n

ASP.NET 2.0的异步页面刷新

asp.net|刷新|页面|异步 ASP.NET 2.0的异步页面刷新功能真得很酷,今天尝试用它解决我的一个应用问题,真是帮了大忙了. 我的页面要向后台的socket服务提交一个查询,首先这是一个可能长时间不返回的操作:其次为了拿到socket服务返回的长度不定.有可能很大的Response数据,我不得不采用了dotNET的IAsyncResult BeginReceive(byte[] buffer, int offset, int size, SocketFlags socketFlags,

ASP.NET 2.0的异步页面刷新真给劲

asp.net|刷新|页面|异步 ASP.NET 2.0的异步页面刷新功能真得很酷,今天尝试用它解决我的一个应用问题,真是帮了大忙了. 我的页面要向后台的socket服务提交一个查询,首先这是一个可能长时间不返回的操作:其次为了拿到socket服务返回的长度不定.有可能很大的Response数据,我不得不采用了dotNET的IAsyncResult BeginReceive(byte[] buffer, int offset, int size, SocketFlags socketFlags,

XMLHTTP+Javascript+Asp写得聊天室,无刷新实现(四)

javascript|xml|聊天室|刷新|无刷新 ########say.asp############## <% Option Explicit dim F,T,sC,cL,E,W,sJResponse.ContentType="text/xml"F=Request.Form ("F")T=Request.Form ("T") sC=Request.Form ("sC")cL=Request.Form ("

XMLHTTP+Javascript+Asp写得聊天室,无刷新实现(五)

javascript|xml|聊天室|刷新|无刷新 这是最重要的一个了.也很大.我的习惯不太好.没有加详细的注释,认真看吧.#########send.asp##############<html> <head><META content="text/html; charset=gb2312" http-equiv=Content-Type> <meta http-equiv='pragma' content='no-cache'><

XMLHTTP+Javascript+Asp写得聊天室,无刷新实现(三)

javascript|xml|聊天室|刷新|无刷新 ################reload.asp############## <%'Response.ContentType="text/xml"Response.Write "<?xml version=""1.0"" encoding=""GB2312""?>" Response.Write "<

XMLHTTP+Javascript+Asp写得聊天室,无刷新实现(二)

javascript|xml|聊天室|刷新|无刷新 ################main.asp###################### <%Response.Buffer=trueResponse.Expires=0userName=Request.Form("username")if username="" then Response.Redirect "index.asp" session("u_name"

XMLHTTP+Javascript+Asp写得聊天室,无刷新实现(一)

javascript|xml|聊天室|刷新|无刷新 使用XML.而无须不断刷新*.ASP.无刷新实现发言的逐条显示.使用Application变量存储聊天记录,所以要需要建立一个虚拟目录服务器端不需要支持XML,只要支持ASP和能建立虚拟目录就可以了. 以下代码在nt4.0+iis4.0上通过.我估计在你的win2000下也差不多吧.如果有问题,请多多赐教:netnice@chinaok.net ##########index.asp##############################