我有一個treeview我用來顯示目錄結構。我正試圖通過在節點擴展上加載子節點來減少加載時間。有沒有辦法做到這一點?ASP.NET TreeView + AJAX
下面是我目前使用填充樹視圖中的代碼:
protected void Page_Load(object sender, EventArgs e) {
BuildTree(Request.QueryString["path"]);
}
private void BuildTree(string dirPath)
{
//get root directory
System.IO.DirectoryInfo rootDir = new System.IO.DirectoryInfo(dirPath);
//create and add the root node to the tree view
TreeNode rootNode = new TreeNode(rootDir.Name, rootDir.FullName);
TreeView1.Nodes.Add(rootNode);
//begin recursively traversing the directory structure
TraverseTree(rootDir, rootNode);
}
private void TraverseTree(System.IO.DirectoryInfo currentDir, TreeNode currentNode)
{
//loop through each sub-directory in the current one
foreach (System.IO.DirectoryInfo dir in currentDir.GetDirectories())
{
//create node and add to the tree view
TreeNode node = new TreeNode(dir.Name, dir.FullName);
currentNode.ChildNodes.Add(node);
//recursively call same method to go down the next level of the tree
TraverseTree(dir, node);
}
foreach (System.IO.FileInfo file in currentDir.GetFiles())
{
TreeNode node = new TreeNode(file.Name, file.FullName);
currentNode.ChildNodes.Add(node);
}
}
@RenanMalkeStigliani你能否解釋一下? – 2013-02-20 21:37:39
你的問題太抽象了,提供更多細節,就像你目前用來加載樹視圖的任何框架JavaScript;樹視圖代碼和你得到的項目數量。 – RMalke 2013-02-20 21:42:42