<%@ Control Language="c#" Inherits="ASPNETExpert.WebControls.Demo.Tree.Advanced.PopulateOnDemand" CodeFile="PopulateOnDemand.ascx.cs" %>
<%@ Register TagPrefix="ecd" Namespace="ASPNETExpert.WebControls.DemoControls" Assembly="ASPNETExpert.WebControls.DemoControls" %>
<%@ Register TagPrefix="ec" Namespace="ASPNETExpert.WebControls" Assembly="ASPNETExpert.WebControls" %>
<table cellpadding=0 cellspacing=0 border=0 width="100%" xmlns:ec="urn:http://aspnetexpert.com/ExpertControls.xsd">
<tr>
<td valign=top>
<ec:ExpertTree id="PopulateOnDemandTree" Skin="XP" runat="server" PopulateOnDemandWaitMessage="Loading. Please wait..." ExpandOnClick="true" CollapseOnClick="true">
<TreeLook Base="XP" Width="220px" Height="500px" Overflow="Scroll" ShowLines="True" />
<Looks>
<ec:TreeNodeLook Id="ParentAnimated" Base="Parent" BindStrategy="OverrideBaseBind">
<SubTree Expand-Effect="GlideTopToBottom" Expand-Duration="150" Collapse-Effect="GlideTopToBottom" Collapse-Duration="150" />
</ec:TreeNodeLook>
</Looks>
</ec:ExpertTree>
</td>
<td valign=top style="PADDING-LEFT:50px">
<ecd:DescriptionView runat="server" ID="Descriptionview1">
<ecd:Description id="Description1" runat="server">
The tree in the example shows the file hierarchy. Only the part of the
hierarchy is loaded on initial page load. Other hierarchy levels are loaded when requested.
</ecd:Description>
<ecd:Description id="Description2" runat="server">
Set <b>PopulateOnDemand="true"</b> in order to raise callback upon a node
expanding and load the node's children. Process <b>NodePopulateOnDemand</b> event
at the server-side.
</ecd:Description>
<ecd:Description id="Description3" runat="server">
Use <b>TreeNode</b> and <b>TreeNodeCollection</b> properties and methods
at the server side to supplement the node collections in the tree. Set node's
<b>PopulateOnDemand</b> property to <b>false</b> to prevent further loadings on demand.
If you want, however, that loading on demand occurs every time the node is expanded
leave <b>PopulateOnDemand</b> property without changes.
</ecd:Description>
<ecd:Description id="Description4" runat="server">
<b>Note</b>, that <b>Populate-On-Demand</b> is similar to <b>Postback-On-Expand</b> but
doesn't cause flicker of the page and preserves its scroll position.
</ecd:Description>
<ecd:Description id="Description5" runat="server">
Use <b>PopulateOnDemandWaitMessage</b> property to set the custom message instead of
default <b>Loading...</b> message.
</ecd:Description>
<ecd:Description id="Description6" runat="server">
<b>PopulateOnDemandViewStateEnabled</b> property controls whether the tree view state is kept
up-to-date between server callbacks. If <b>PopulateOnDemandViewStateEnabled</b> is turned on,
(by default, it is), disable event validation for the page:
<pre class="aspcode">
<ecd:SyntaxHighlight runat="server" ContentType="ASPX">
<%@ Page EnableEventValidation="false" %>
</ecd:SyntaxHighlight>
</pre>
</ecd:Description>
</ecd:DescriptionView>
</td>
</tr>
<tr>
<td colspan="2" valign=top style="PADDING-TOP:6px">
<asp:Button Runat=server Text="PostBack" id=Button1 />
</td>
</tr>
</table>
<ec:CodeViewTab id="CodeViewTab1" runat="server">
<ec:TabItem runat="server" Text="aspx" ID="Tabitem1">
<pre class="aspcode">
<ecd:SyntaxHighlight runat="server" ContentType="ASPX" OutputFile="Advanced/PopulateOnDemand.ascx" ID="Syntaxhighlight1"/>
</pre>
</ec:TabItem>
<ec:TabItem runat="server" Text="C#" ID="Tabitem2">
<pre class="aspcode">
<ecd:SyntaxHighlight runat="server" ContentType="C#" OutputFile="Advanced/PopulateOnDemand.ascx.cs" ID="Syntaxhighlight2"/>
</pre>
</ec:TabItem>
<ec:TabItem runat="server" Text="VB" ID="Tabitem3">
<pre class="aspcode">
<ecd:SyntaxHighlight runat="server" ContentType="VB" OutputFile="Advanced/PopulateOnDemand.ascx.vb" ID="Syntaxhighlight3"/>
</pre>
</ec:TabItem>
</ec:CodeViewTab>
namespace ASPNETExpert.WebControls.Demo.Tree.Advanced
{
using System;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.IO;
using ASPNETExpert.WebControls;
///
/// Summary description for LoadOnDemand.
///
public partial class PopulateOnDemand : System.Web.UI.UserControl
{
protected void Page_Load(object sender, System.EventArgs e)
{
if(PopulateOnDemandTree.Nodes.Count == 0)
{
BuildNodes(PopulateOnDemandTree.Nodes, Server.MapPath(""));
}
}
private void BuildNodes(ASPNETExpert.WebControls.TreeNodeCollection nodes, string filePath)
{
nodes.Clear();
foreach(string dir in Directory.GetDirectories(filePath))
{
ASPNETExpert.WebControls.TreeNode treeNode = new ASPNETExpert.WebControls.TreeNode(GetLastName(dir));
treeNode.Value = dir;
treeNode.PopulateOnDemand = true;
nodes.Add(treeNode);
treeNode.Look.Base = "ParentAnimated";
}
foreach(string file in Directory.GetFiles(filePath))
{
ASPNETExpert.WebControls.TreeNode treeNode = new ASPNETExpert.WebControls.TreeNode(GetLastName(file));
nodes.Add(treeNode);
treeNode.BindLook();
}
}
private string GetLastName(string filePath)
{
return filePath.Substring(filePath.LastIndexOf('\\') + 1);
}
private void PopulateOnDemandTree_NodePopulateOnDemand(object sender, ASPNETExpert.WebControls.TreeNodeEventArgs eventArgs)
{
BuildNodes(eventArgs.Node.Nodes, eventArgs.Node.Value);
eventArgs.Node.PopulateOnDemand = false;
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
this.PopulateOnDemandTree.NodePopulateOnDemand += new ASPNETExpert.WebControls.TreeNodeEventHandler(this.PopulateOnDemandTree_NodePopulateOnDemand);
}
#endregion
}
}