<%@ 页面语言="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(对象发送者,TreeNodeEventArgs e)
{
if (IsCallback)
if (e.Node.ChildNodes.Count == 0)
{
LoadChildNode(e.Node);
}
}
private void LoadChildNode(TreeNode 节点)
{
DirectoryInfo 目录;
目录 = new DirectoryInfo(node.Value);
foreach(目录中的DirectoryInfo sub.GetDirectories())
{
TreeNode subNode = new TreeNode(sub.Name);
subNode.Value = sub.FullName;
尝试
{
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"; }
节点.ChildNodes.Add(子节点);
}
foreach (目录中的FileInfo fi.GetFiles())
{
TreeNode 子节点 = new TreeNode(fi.Name);
节点.ChildNodes.Add(子节点);
}
}
</script>
<html xmlns=" http://www.w3.org/1999/xhtml ">
<头runat =“服务器”>
<标题>无标题页面</标题>
</头>
<body bgcolor =“白色”>
<form id="form1" runat="服务器">
<div>
<asp:treeview ID="Treeview1" runat="server" ImageSet="XPFileExplorer" AutoGenerateDataBindings="false" ExpandDepth=0
OnTreeNodePopulate="Treeview1_TreeNodePopulate"
>
<SelectedNodeStyle BackColor="#B5B5B5"></SelectedNodeStyle>
<节点>
<asp:TreeNode Value="C:" Text="C:" PopulateOnDemand="true" SelectAction="选择" NavigateUrl="#" >
</asp:树节点>
</节点>
<NodeStyle VerticalPadding="2" Font-Names="Tahoma" Font-Size="8pt" HorizontalPadding="2"
ForeColor="黑色"></NodeStyle>
<HoverNodeStyle Font-Underline="True" ForeColor="#6666AA"></HoverNodeStyle>
</asp:树视图>
</div>
</形式>
</正文>
</html>