Home - Forums-.NET - FlyTreeView (ASP.NET) - Create FlyNodeType during run time

FlyTreeView (ASP.NET)

Technical support and KB related to the FlyTreeView control

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

Create FlyNodeType during run time
Link Posted: 11-Aug-2008 19:32
Hi all,

Can anyone guide me how to create FlyNodeType which contains a Link button during run time? I'm able to create a link button control but doesn't know how to create and assign to the ContentTemplate of that FlyNodeType.

Any help will be much appreciate

Thanks in advance.
Link Posted: 12-Aug-2008 08:03
When you create a FlyNodeType, you can simply edit ContentTemplate using designers (see menu of control), or code editor.

You can use binding expressions like  when binding node data and/or use FlyTreeView.NodeDataBound event to customize result.
Link Posted: 12-Aug-2008 16:56
Hi EvgenyT,

Thanks for reply.

What I mean here is to generate the tree view in Code behind or during the design time.

I had figured out how to create a NodeType but just don't know how to create the content template which consist of a Link Button.

Thanks.
Link Posted: 12-Aug-2008 18:56
So you need to create subcontrols of nodes at runtime, don't you ?

There's FlyTreeNode.ContentContainer property. It is a control that hosts server-side controls of a node.
Anyway it is not accessible when node doesn't use FlyNodeType ContentTemplate. It is null in this case.
This approach has some reasons. ASP.NET runtime restores controls state at postback, so FlyTreeView  every postback for every node provides control hierarchy for every node (taken from FlyNodeType.ContentTemplate).

So from my point of view, you can try to use ContentTemplate that contains and (if you need) customize it at NodeDataBound event.

Alternatively, you can create your custom control that overrides CreateChildControls() method and host it in ContentTemplate.
In any case FlyNodeType with ContentTemplate is required for nodes with server controls.

Also, there's a demo with some code related to server templates:
http://www.9rays.net/asp.net_2/treeview/Demo_ServerTemplates.aspx
Link Posted: 12-Aug-2008 22:36
Hi,

I still confuse on how to do this, maybe you all can take a look on the below code:

In ASPX page:

                    IsCheckbox="True" OnNodeEventJavascript="nodeEventHandler" Width="100%"
                    Padding="1px" FadeEffect="True" BorderColor="Silver" BorderWidth="0px" CanBeSelected="false"
                    ContentClickTogglesCheckbox="false" ContentClickExpands="false"
                    OnNodeDataBound="flyTreeView_NodeDataBound" OnPopulateNodes="flyTreeView_PopulateNodes">
                    
                        
                            
                                
                            
                        
                    

                    
                    
                


No node is created in aspx page, and when user click a button on the page, it'll post back to generate the node as below:

In aspx.cs:

                                FlyTreeNode ftn = new FlyTreeNode();
                                ftn.Text = "ABC";
                                ftn.Value = "ABC";
                                ftn.NodeTypeID = "LoadProcess";
                                ftv.Add(ftn);

FlyTreeNode ftn1 = new FlyTreeNode();
                                ftn1.Text = "DEF";
                                ftn1.Value = "ABC";
                                ftn1.NodeTypeID = "LoadProcess";
                                ftv.Add(ftn1);


The above will loop a few times to create different node and each node is having a linkbutton where user can click to open other page. In other words, when user click on each node, different page can be opened. I need the node to generate during runtime because I can't program it at design time. If I run the above, I can get two nodes display but without any wording on it.

Btw, I'm not using DataBinding to generate the node. The above generation is happen under onclick event of a button.

Someone please help me on the above because I really stuck at this stage.

Thanks a lot.
Link Posted: 15-Aug-2008 01:02
I create a test page with your code (bit modified): Default6.aspx: [code] <%@ Register Assembly="NineRays.WebControls.FlyTreeView" Namespace="NineRays.WebControls" TagPrefix="NineRays" %> Untitled Page
LinkButton
[/code] and Default6.aspx.cs: [code]using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using NineRays.WebControls; public partial class Default6 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) { FlyTreeNode ftn = new FlyTreeNode(); ftn.Text = "ABC"; ftn.Value = "ABC"; ftn.NodeTypeID = "LoadProcess"; ftv.Nodes.Add(ftn); FlyTreeNode ftn1 = new FlyTreeNode(); ftn1.Text = "DEF"; ftn1.Value = "ABC"; ftn1.NodeTypeID = "LoadProcess"; ftv.Nodes.Add(ftn1); } }[/code] When I click button, it adds 2 nodes that uses ContentTemplate. How do I need to modify the code to reproduce your issue?