Click here to Skip to main content
Click here to Skip to main content
Articles » Web Development » ASP.NET » General » Downloads
 
Add your own
alternative version
Go to top

DHTML Tree View of Arbitrary Depth using AJAX

, 25 Aug 2005
This article provides a gentle introduction to AJAX by applying that technology to significantly enhance a tree previously rendered using JavaScript.
ajax_treeview_src.zip
ajax_treeview_src
ajax_treeview_src11
Global.asax
img
folder_closed.gif
folder_open.gif
minus.gif
plus.gif
transparent.gif
ajax_treeview_src20
App_Code
App_Data
img
folder_closed.gif
folder_open.gif
minus.gif
plus.gif
transparent.gif
ajax_treeview_src11.zip
img
folder_closed.gif
folder_open.gif
minus.gif
plus.gif
Thumbs.db
transparent.gif
Global.asax
// Copyright (c)2005 Rewritten Software.  http://www.rewrittensoftware.com
// This script is supplied "as is" without any form of warranty. Rewritten Software 
// shall not be liable for any loss or damage to person or property as a result of using this script.
// Use this script at your own risk!
// You are licensed to use this script free of charge for commercial or non-commercial use providing you do not remove 
// the copyright notice or disclaimer.

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

/// <summary>
/// Tree node responder, collaborates in an AJAX style relationship with TreeView
/// </summary>
public partial class TreeFill : System.Web.UI.Page
{
	
    protected void Page_Load(object sender, EventArgs e)
    {
    }

    /// <summary>
    /// Render the nodes attached to a node at a specific level in the tree
    /// </summary>
    /// <param name="writer"></param>
    protected override void Render(HtmlTextWriter writer)
    {
        string treeID = Request["tree"];
        if (treeID == null)
            throw new HttpException("Tree identifier not found in request during delay load.");

        Tree tree = (Tree)Session["tree" + treeID];
        if (tree == null)
            throw new HttpException("Tree was not found in session during delay load.");

        string nodeID = Request["id"];
        if (nodeID == null)
            throw new HttpException("Node id null in delay load.");
        
        // Locate and output the requested node
        bool found = false;
        OutputTreeNode(nodeID, treeID, writer, tree.Root, ref found);
    }
    
    /// <summary>
    /// Recursive: Search the tree for the relevant node and output its children
    /// </summary>
    /// <param name="nodeID">parent node id</param>
    /// <param name="treeID">id of this tree</param>
    /// <param name="writer">output writer</param>
    /// <param name="node">starting node</param>
    /// <param name="found">found yet or not</param>
    void OutputTreeNode(string nodeID, string treeID, HtmlTextWriter writer, TreeNode node, ref bool found)
    {
        // We found the node, output its children, and stop.
        if (nodeID == node.ID)
        {
            foreach (TreeNode child in node.Children)
                child.WriteNode(writer, treeID, true);
            found = true;
            return;
        }

        // Not found yet, search children for the node.
        if (!found)
            foreach (TreeNode child in node.Children)
                OutputTreeNode(nodeID, treeID, writer, child, ref found);
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

Adrian Holland
Architect Webefinity
Australia Australia
Adrian is current the Solution Architect at CubeBuild.com.
 
The core of CubeBuild is a website and application platform that is pluggable into ASP.NET MVC. Any MVC application can have content authoring added to its pages with little effort, and new content types are created using IronPython.NET open source components.
 
We are currently deploying a Point of Service (Web based POS) built on CubeBuild which allows a single web channel for face-to-face sales, and sales through your online store. All from a single inventory base, and from any device.

| Advertise | Privacy | Mobile
Web01 | 2.8.140922.1 | Last Updated 26 Aug 2005
Article Copyright 2005 by Adrian Holland
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid