Asp.net 2.0 Treeview 无限级无刷新示例
2007-01-11 17:21:12 来源:WEB开发网<%@ 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>
- ››asp.net页面弄成伪静态页面
- ››Asp.net 中将汉字转换成拼音的方法
- ››ASP.NET及JS中的cookie基本用法
- ››ASP.NET获取MS SQL Server安装实例
- ››asp.net实现调用百度pai 在线翻译英文转中文
- ››ASP.NET页面选项进行提示判断
- ››Asp.net定时执行程序
- ››ASP.NET中利用DataList实现图片无缝滚动
- ››ASP.NET验证控件RequiredFieldValidator
- ››ASP.NET中使用System.Net.Mail发邮件
- ››ASP.NET中获取用户控件中控件的ID
- ››ASP.NET中FileBytes写成文件并存档
赞助商链接