Dynamically Expandable TreeView Nodes

I have a TreeView with Nodes that are added in client-side code (I'm loading it with a list of drives/directories/files from the local file system). I want to dynamically load the contents of the directories dynamically, much like I've done with Server-side callback. However, if I select ExpandMode = TreeViewNodeExpandMode.ClientSide, the "+" doesn't appear next to the node. How can I get the "+" to appear in this case. Eventually, I want my ClientSideOnNodeExpand JScript function called when the user clicks on the "+"..


2 Replies

NE Neal April 18, 2008 03:14 PM UTC

Ok, I found a workaround. Whenever I create a folder, I also create a dummy node under it with text of "". Then, when the user expands the folder, I check for a single node with the above text. If it exists, I delete it and load the contents of the directory into the tree. I used the angle brackets above since they are not valid in a filename.

It seems like there should be a better way to accomplish this; but, this will do for now.




JA Janagan Syncfusion Team April 24, 2008 02:34 PM UTC


Hi Neal,

If your intention is to load the childnode dynamically by invoking the clientside javascript, it can be achieved via a callback panel but you cannot make the "+" sign to appear by setting the expandmode to client side because When the expand mode is set to Client side, any callback or postback will not occur on expanding node. Please refer the code below for dynamically loading the child node via callback panel:

function nodeExpand(node)
{

document.getElementById(''eventDisplay'').innerHTML = "Expanded ''" + node.Text + "''" ;
CallbackPanel1.callback(node.Text);
}

code behind:

protected void CallbackPanel1_CallbackRefresh(object sender, CancellableCallbackEventArgs e)
{
foreach (TreeViewNode node in this.TreeView1.Items)
{

if (node.Text == e.CallbackArgument)
{
TreeViewNode childnode = new TreeViewNode();
childnode.Text = "New Text";
node.Items.Add(childnode);
}



}
}



Please refer the sample in the link below which illustrates the above:

http://websamples.syncfusion.com/samples/Tools.Web/6.2.0.40/cs/main.htm

Please try running the sample and if still the issue exists, could you please try reproducing it in the above sample so that we could sort out the cause and provide you a better solution?

Regards,
Janagan.



Loader.
Up arrow icon