Home - Forums-.NET - FlyTreeView (ASP.NET) - Accessing the key values in a selected node

FlyTreeView (ASP.NET)

Technical support and KB related to the FlyTreeView control

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

Accessing the key values in a selected node
Link Posted: 04-Dec-2007 08:23
I have a flytreeview that has a control that is AutoApplyAtLeafs=true. I can get to the ourControl:CheckBoxes values just fine, but I need to get the values for the selected node key field. How can I do this? I didn't see any samples of accessing the values for the nodes in your examples. Thanks in advance.

                                  BorderColor="Silver" BorderWidth="1px" Height="320px" Padding="2px"
                    CanBeSelected="False" SlideEffect="True" WideCell="True" ContentClickCollapses="true"
                    DisableSelect="false">
                                            Padding="0px;5px;0px;0px" />
                    
                    
                  
                        
                        
                        
                    
                    
                        
                            
    //this is a control of 5 checkboxes
                            
                        
                    
                
Link Posted: 04-Dec-2007 08:32
What do you mean by "key field". Is it FlyTreeNode.ID property, or FlyTreeNode.Value property or anything else?
Link Posted: 04-Dec-2007 08:44
I guess what I mean is that I need to access some value in the treenode that I can set to correspond to my primary key of my dataset, ie, the tree would look like this:

ParentNode
   ChildNode
     //these are checkboxes associated with the child node
    Alternate   Refueling   Regular   Provisional   ETOPS Alternate   Polar Ops

and I need to know if I have access to an unique id for the child node that would correspond to the primary key of the data data retrieved from my database that fills the tree.
Link Posted: 04-Dec-2007 09:18
So, you need to store something in node.Value?

Probably you need to bind your data primary key to node.Value (use ValueField for FlyNodeBinding).
Then, you can get it by treeview.SelectedNode.Value.

I'm not sure that I understand your idea
Link Posted: 05-Dec-2007 01:30
The idea is that the user can navigate through the tree to a specific value and then update the checkboxes for that value. So I would need the primary key value for that specific value in the tree so I can then update the checkbox values in the database.

Do you have any documentation/examples for retrieving values after a node is selected? All I have seen in your online examples is setting up the tree. The example I am interested in is the Demos: Data Binding To Tabular Data. You show how to data bind the tree, but not how to get the checked values from the nodes.
Link Posted: 05-Dec-2007 01:46
Every node has its node.ContainerControl - the control that hosts node controls created with server-side template.

So if you need to get to your server checkbox control of some node, then you need to look what you have in
node.ContainerControl, or possibly use
CheckBox yourNodeCheckbox = (CheckBox)node.ContainerControl.FindControl("controlID");

Do you have any documentation/examples for retrieving values after a node is selected?

If the node is selected, you can get it with treeview.SelectedNode. So you can get any property from this node.
In your case:
treeview.SelectedNode.ContainerControl.Controls[0] - this will be your CheckBoxes instance for the node.


So you can get to any property of any node, browse node controls (your CheckBoxes).
Link Posted: 05-Dec-2007 01:56
That is fine, but I also need to know what the value of the node is. In the example the tree is loaded as follows:

            DataSet dSet = new DataSet("DataBase");
            DataTable dTable = new DataTable("Orders");
            dSet.Tables.Add(dTable);

            dTable.Columns.Add("ID");
            dTable.Columns.Add("OwnerID");
            dTable.Columns.Add("Title");
            dTable.Columns.Add("Selected");

            // Add nodes (OwnerID is null for root nodes)
            dTable.Rows.Add(new object[] { 1, null, "Developer Tools"});
            dTable.Rows.Add(new object[] { 2, 1, "Spices.Net", true });
            dTable.Rows.Add(new object[] { 3, 1, "Spices.Obfuscator" });
            dTable.Rows.Add(new object[] { 4, 1, "Spices.Decompiler" });
            dTable.Rows.Add(new object[] { 5, null, ".Net Controls" });
            dTable.Rows.Add(new object[] { 6, 5, "FlyGrid.Net" });
            dTable.Rows.Add(new object[] { 7, 5, "FlyTreeView for ASP.NET 1.1", false });
            dTable.Rows.Add(new object[] { 8, 5, "FlyTreeView for ASP.NET 2.0", true });


            // Call FlyTreeView.ConvertTabularDataToHierarchical method to convert into hierarchical datasource
            IHierarchicalEnumerable hierarchicalData =
              NineRays.WebControls.FlyTreeView.ConvertTabularDataToHierarchical(dSet, "Orders", "ID", "OwnerID");

            // Bind the treeview
            flyTreeView.DataSource = hierarchicalData;
            flyTreeView.DataBind();

Is there a way to access the dTable column of "ID" after the databinding has occured? Does that value exist in the treenode? I am assigning the "ID" column as my Primary Key value.
Link Posted: 05-Dec-2007 10:35
What you need is to use ValueField="ID" for you FlyNodeBinding.
This way the Value property will keep ID value.