.net Treeview无限级无刷新示例

发表于:2007-09-07来源:作者:点击数: 标签:
<%@ 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, T
<%@ 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=sr=TreeView_XP_Explorer_ParentNode.gif&t=632242003305625000"; }
node.ChildNodes.Add(subNode);

}

[1] [2]下一页

原文转自:http://www.ltesting.net