Home - Forums-.NET - FlyTreeView (ASP.NET) - Adding more data fields to FlyTreeView

FlyTreeView (ASP.NET)

Technical support and KB related to the FlyTreeView control

This forum related to following products: FlyTreeView for ASP.NET

Adding more data fields to FlyTreeView
Link Posted: 05-Feb-2008 03:47
Hi - Is there a way to add more (atleast 1 more) datamember field to the Databinding of FLyTreeView using XML DataBindings? What I mean is Say my DataMember is "Product" and TextField="Notebook" ValueField="100"...then can I have one more ? something like.....may be...TargetField="" etc...

Any help would be much appreciated.

Thanks
Link Posted: 05-Feb-2008 03:57
FlyNodeBinding class contains a set of XXXXField properties, but not all.

If you need to bind node.NavigateTarget or NaviagteUrl, etc. Or have some complex binding logic.
Then you can simply handle the FlyTreeView.NodeDataBound event.
It provides the FlyTreeNodeEventArgs argument, so you can use something like this:

e.Node.NavigateTarget = DataBinder.Eval(e.Node.DataItem, "yournavigatetargeturlFIELD");
Or, instead, you can cast e.Node.DataItem to the type of data item you provide and assign node properties the way you want  

This is a very powerful way to customize every node when it is data bound - you can do with it whatever you want =)
Link Posted: 05-Feb-2008 04:15
Thanks EvengyT - But my issue here is that I want to one of My XML DataMember filed to populate once the FlyTreeView parses the XML.  already have 2 fields parsing, one for TextField and one for ValueField, I need a third for: InStock="1" something like that...how can I do that? I know I can use my value field and use some perator logic and add it to my ValueField, but I don't want to do that I want one more, something like NewField="InStock", which renders the appropriate value from the XML, whether 1 or 0

I am not using any Navigation, so the users don't get redirected anywhere. I am using more client side stuff and hence NavigationURL doesn't do the purpose.

A snippet/example would be appreciated.  

Thanks
Link Posted: 05-Feb-2008 04:23
So you need to put some extra data to the node when data binding?
So far I see it can be done through NodeDataBound event and node.Attributes collection.

For example you can set like this (NodeDataBound event content):

e.Node.Attributes["mySomeCustomData"] = ((XmlElement)e.Node.DataItem).Attributes["yourXmlAttribute"].Value;

the node.Attributes is available at client-side through node.getAttribute node.setAttribute functions.

Also, you have a node.Tag property that can contain arbitrary serializable object. This property is not available at client-side.
Link Posted: 05-Feb-2008 04:58
Hi Thanks. I tried thsi below, but I get an error on XMLElement. Could you help me please.

Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:

Protected Sub treeViewCakeLayers_NodeDataBound(ByVal sender As System.Object, ByVal e As NineRays.WebControls.FlyTreeNodeEventArgs)
    e.Node.Attributes("IsSecurement") = DirectCast((DirectCast(e.Node.DataItem, IHierarchyData)).Item, XmlElement).Attributes("IsSecurement").Value
       End Sub
Link Posted: 05-Feb-2008 06:26
Try this code instead (I debugged it to make it finally work for me   ):

e.Node.Attributes["IsSecurement"] = ((XmlElement)((IHierarchyData)e.Node.DataItem).Item).GetAttribute("IsSecurement");


As you see e.Node.DataItem does not directly contain the XmlElement, but a IHierarchyData object instead.
So we need its Item property to finally get the XmlElement bound to the node.
Link Posted: 05-Feb-2008 09:41
Thanks. Worked like a charm!