<%@ ページ言語="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);
}
プライベート
void LoadChildNode(TreeNode ノード)
{
DirectoryInfo ディレクトリ。
ディレクトリ = 新しいディレクトリ情報(node.Value);
foreach (directory.GetDirectories() の DirectoryInfo サブ)
{
TreeNode サブノード = 新しい 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 サブノード = 新しい TreeNode(fi.Name);
ノード.ChildNodes.Add(サブノード);
}
}
</script>
<html xmlns=" http://www.w3.org/1999/xhtml " >
<head runat="サーバー">
<title>無題のページ</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>
<ノード>
<asp:TreeNode Value="C:" Text="C:" PopulateOnDemand="true" SelectAction="Select" NavigateUrl="#" >
</asp:ツリーノード>
</ノード>
<NodeStyle VerticalPadding="2" Font-Names="Tahoma" Font-Size="8pt" horizontalPadding="2"
ForeColor="Black"></NodeStyle>
<HoverNodeStyle Font-Underline="True" ForeColor="#6666AA"></HoverNodeStyle>
</asp:ツリービュー>
</div>
</form>
</body>
</html>