Hi,
I'm using a WebTree with an XmlDataSource. In code I'm setting the Data property of the XmlDataSource to a valid XML string. This XML string has one rootnode. The WebTree is correctly bound to the XML string. But now I want to hide the root node of the XML string in the WebTree. Is that possible?
thanks,Jeroen
I need to do the same thing. Can someone post a solution here?
Yes, I believe it is possible (I hope I get the scenario right). When binding any ASP.NET server control to declarative datasources like XmlDataSource, it is often bound at a very late point in the page lifecycle, typically after Page_Load and after postback event handlers, sometimes even after OnPreRender.
So you can wire the OnPreRenderComplete event (always firing after binding to declarative datasources) and remove the first root node there:
protected override void OnPreRenderComplete(EventArgs e) { base.OnPreRenderComplete(e);
UltraWebTree1.Nodes.RemoveAt(0); }
Alternatively, you can force databinding to your XmlDataSource explicitly by calling DataBind() on the treeview in, say, Page_Load, and then remove the node. For example:
protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { UltraWebTree1.DataBind(); UltraWebTree1.Nodes.RemoveAt(0); } }
Please, let me know if this is not helpful in your setup and if I am missing something in your scenario.
If we do this way, we will remove all the ChildNodes. how to just hide or remove root node when we display WebTree Control?
mac
Not sure if anyone found this or not as its been a few years since this thread was active but since this is the first thread I found in searching for this question, I figured I would add it here...
This seems to work quite fine... as I have two controls on my page, a XmlDataSource and an UltraWebTree. In my code behind during the PreRender (or where ever you want to do it, such as Load or another event) I have the following:
MyXmlDataSource.XPath = "//SomeNodes/*[@enabled!='false']";
MyXmlDataSource.Data = "<SomeNodes><Node1 enabled=\"false\"><Node11><Node111 /></Node11></Node1><Node2 enabled=\"true\"><Node21><Node211 /></Node21><Node22><Node221 /></Node22></Node2></SomeNodes>"
;
MyUltraWebTree.DataSource = MyXmlDataSource;
MyUltraWebTree.DataBind();
This will set the root xml data presented from the XmlDataSource to be all the child nodes of the root Location node that dont have a attribute "enabled" equal to "false". So as long as the XPath selects the children of the root node, that's what your tree should show. You dont need the "[@enabled!='false']" parth of the XPath but I just thought it useful to show for easily filtering the tree content.
Baydon