I'm using the WebDataTree with several nodes created from a sitemap source. When one of the nodes is clicked it refreshes the page and the datatree collapses back to the original state. is there anyway to return or expand back to the node that was clicked once the page is refreshed. Can't seem to find any code to expand the data tree in my code??
Hi,
You can easily expand out to a node on the server. You will need to figure out which node was clicked, but then you can call node.ExpandAnscestors(); You can also set node.Expanded = true; for a node to be expanded. So, I would try to put this code somewhere in the page load. Let us know if this works or you need more help.
regards,David Young
It doesn't work. I tried both ExpandAncestors and Expanded = true in the NodeClick event and in PreRender and the tree always return back to its initial state. Even if it worked, it is not enough because a user can click on any page link to get to another page or write down the url himself, and you won't get any event.
I added this in the DataBound event and it worked:
var url = Page.Request.Url.AbsolutePath;
foreach (DataTreeNode node in AllNodes)
{
if (node.NavigateUrl == url)
node.Expanded = true;
node.ExpandAnscestors();
}
By the way, tree.AllNodes is an ArrayList. Is there a reason it is not List<DataTreeNode>?
As far as I know, this control wasn't even exist in the 1.1 framework.
Version 10.1, fix 2039, VS 2010, .NET 4.
Hi Amiram,
Does the above code work for the Webdatatree control having the Infragistics v13.1? If not can you provide a snippet of code that works for the current version of Webdatatree control.
Regards
Shinoy
Thanks Amiram. Your code worked well. Here's my DataBound event to select a node and open it. This is using a SiteMapDataSource (but that doesn't really matter).
protected void navTree_DataBound(object sender, EventArgs e) { //select the current node in the tree //BTW, NodeBound happens before DataBound var currentUrl = Page.Request.Url.PathAndQuery; foreach (DataTreeNode node in ((WebDataTree)sender).AllNodes) { if (node.NavigateUrl == currentUrl) { node.DataTree.SelectedNodes.Clear(); node.Selected = true; node.Expanded = true; node.ExpandAnscestors(); break; //get out of this foreach loop } } }