<%@ 頁面語言="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>