Home - Forums-.NET - FlyTreeView (ASP.NET) - Using server templates on the fly.

FlyTreeView (ASP.NET)

Technical support and KB related to the FlyTreeView control

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

Using server templates on the fly.
Link Posted: 24-Apr-2008 04:24
I am building a custom control around the FlyTreeView.  In an instance of this custom control I would like to have a text box appear in a node of the tree.  I do not want the user (of the custom control) to have to specify a template for the node; nor should they see the template if the template is auto-generated by the control.

My approach for doing this was to create a template in code by creating and instantiating a class that implements the ITemplate interface.  I then create a FlyNodeType and set the ContentTemplate property to the new template object.  I then try to set the NodeType property of the appropriate FlyTreeNode to reference the created FlyNodeType, but this does not work as the NodeType property is read-only.

Is what I am trying to do possible?  If so, please offer some advice as to how to go about it.

Thank you in advance,
Jeremy
Link Posted: 24-Apr-2008 04:37
I apologize to anyone I might have sent on a wild goose chase.  After posting this subject the solution presented itself to me.  What I did is this:  after creating the FlyNodeType object I set the ID property.  I then add the type object to the NodeTypes collection property of the FlyTreeView itself.  Then when I set up the node, instead of setting the NodeType property, I set the NodeTypeID property which is read-write.

The question that remains is this:  Can I derive my template class from a template class that is already in use by the FlyTreeView control so that I can still have radio buttons, check boxes, etc. exhibit all of the same properties and behaviors (i.e. data binding, styles) as are exhibited by other nodes?

Thanks again,
Jeremy
Link Posted: 24-Apr-2008 22:25
Jeremy,

By default, tree nodes do use templates or any class, it just renders node.Text (or some additional code if case if radiobutton/checkbox is present). This approach allows to create nodes at client-side, load nodes on demand, etc.
So there's no class to derive from, and you have to implement your own template if you need it to have custom server-side controls in it.
Link Posted: 24-Apr-2008 22:27
Also, you can handle FlyTreeView.NodeDataBound to set up created nodes (its controls that were created from template) using the node.DataItem property.