Home - Forums-.NET - FlyTreeView (ASP.NET) - Dataset with multiple tables

FlyTreeView (ASP.NET)

Technical support and KB related to the FlyTreeView control

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

Dataset with multiple tables
Link Posted: 20-Feb-2008 19:03
Hi,

I have searched through the FAQs and looked at the examples and can't find anthing that points me to how to use a dataset with more than one table.

I have a dataset with three tables.

Table1 = Employees
Table2 = Orders
Table3 = OrderItems

Employees has a PK of EmpID
Orders as a PK of OrderID and a FK of EmpID (indicating who placed the order.)
OrderItems as a PK of ItemID and a FK of OrderID (indicating the items that were included in a given order.)

I would like the tree to display something like:

Dave
   Order 1
        Order 1 Items
   Order 2
        Order 2 Items
Mike
   Order 5
        Order 5 Items
   Order 7
       Order 7 Items
Sue
   Order 11
        Order 11 Items

Each node might be a hyperlink to a details page...

Can anyone please provide an example of how I can use a DataSet with these three tables?

Any help would be greatly appreciated!

Dave
Link Posted: 21-Feb-2008 02:33
It looks like you need to bind each level separately and handle the NodeDataBound event to bind next level (use Node.Nodes.DataSource and Node.Nodes.DataBind()).

To add a hyperlink to some node, you need to use the node.NavigateUrl property.
Link Posted: 21-Feb-2008 04:20
Thanks for the info and direction.

I'm completely new to this control.  Is there anyone willing to bang out a small code snippet as an example of how I would use the previously mentioned approach?
Link Posted: 21-Feb-2008 04:59
Okay.

Here is the code in ASPX:
    BorderColor="Silver" BorderWidth="1px" Height="320px" Width="280px" Padding="1px"
    FadeEffect="True" WideCell="True" ExpandLevel="1"  ContentClickCollapses="true" OnNodeDataBound="flyTreeView_NodeDataBound">
            RowHeight="18px" />
    
    
        
        
    
    
        
    


And the code-behind:
using System;
using System.Data;
using System.Web;
using System.Web.UI;
using NineRays.WebControls;

public partial class Demo_DataBinding_Tabular : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            // Create sample data
            DataTable dTable = new DataTable("Orders");

            dTable.Columns.Add("ID");
            dTable.Columns.Add("Title");
            dTable.Columns.Add("URL");

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


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

        }
    }

    private IHierarchicalEnumerable CreateHierarchichal(DataTable datatale)
    {
        // this is the way we can create IHierarchicalEnumerable from every table
        return FlyTreeView.ConvertTabularDataToHierarchical(datatale, "ID", "ID");
    }
    protected void flyTreeView_NodeDataBound(object sender, FlyTreeNodeEventArgs e)
    {
        if (e.Node.Level > 1) return;


        // THERE SHOULD SOME CALL TO DATA SOURCE TO GET VALID DATA FOR CHILD NODES
            DataTable dTable = new DataTable("Orders");

            dTable.Columns.Add("ID");
            dTable.Columns.Add("Title");
            dTable.Columns.Add("NewURLField");

            // Add nodes (OwnerID is null for root nodes)
            dTable.Rows.Add(new object[] { 1, "Developer Tools", "http://www.9rays.net/"});
            dTable.Rows.Add(new object[] { 2, "Spices.Net" });


        // for every created node
        e.Node.ChildNodes.DataSource = CreateHierarchichal(dTable);
        e.Node.ChildNodes.DataBind();
    }
}



Of course, there're some unneeded stuff in its setting (I took the standard demo to create it), but the general approach seems to be visible.
Link Posted: 21-Feb-2008 10:50
That's Great! Just what I was looking for... However, when I let this run past level 1 (two levels) IE hangs. I debugged on the server side and the tree control seems to populate just fine. But when the last node is populated, the browser comes up and just hangs... Is there a limit to how many nodes the tree control can contain? Any thoughts? [code] <%@ Register Assembly="NineRays.WebControls.FlyTreeView" Namespace="NineRays.WebControls" TagPrefix="NineRays" %> Untitled Page
[/code] [code] Imports System Imports System.Data Imports System.Web Imports System.Web.UI Imports NineRays.WebControls Imports DAL Partial Class HierarchyByTree Inherits System.Web.UI.Page Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load If Not IsPostBack Then ' Get Level One Data (Clients) Dim ClientsAdapter As New QuantMTableAdapters.ClientOrgTableAdapter() Dim ClientsTable As QuantM.ClientOrgDataTable ' Get all of the Clients ClientsTable = ClientsAdapter.GetClients() ClientsTable.DefaultView.Sort = "Name" ' Bind the treeview mClientTreeFTV.DataSource = CreateHierarchichal(ClientsTable, "ClientOrgID") mClientTreeFTV.DataBind() End If End Sub Private Function CreateHierarchichal(ByVal datatale As DataTable, ByVal IDFieldName As String) As IHierarchicalEnumerable ' this is the way we can create IHierarchicalEnumerable from every table Return FlyTreeView.ConvertTabularDataToHierarchical(datatale, IDFieldName, IDFieldName) End Function Protected Sub mClientTreeFTV_NodeDataBound(ByVal sender As Object, ByVal e As FlyTreeNodeEventArgs) Dim NodeLevel As Integer = e.Node.Level Dim sNodeTitle As String = e.Node.Text Dim sNodeKeyID As String = e.Node.Value Dim dTable As DataTable = Nothing Dim IDFieldName As String = "" If e.Node.Level > 1 Then Return End If Select Case NodeLevel Case 0 ' Clients ' get child plans Dim ClientOrgID As New Guid(sNodeKeyID) Dim PlansAdapter As New QuantMTableAdapters.PlanTableAdapter() Dim PlansTable As QuantM.PlanDataTable PlansTable = PlansAdapter.GetPlansByClientOrgID(ClientOrgID) IDFieldName = "PlanID" dTable = PlansTable Case 1 ' Plans ' get child Portfolios Dim PlanID As New Guid(sNodeKeyID) Dim PortfolioAdapter As New QuantMTableAdapters.PortfolioTableAdapter() Dim PortfoliosTable As QuantM.PortfolioDataTable PortfoliosTable = PortfolioAdapter.GetPortfoliosByPlanID(PlanID) IDFieldName = "PortfolioID" dTable = PortfoliosTable End Select If dTable.Rows.Count > 0 Then dTable.DefaultView.Sort = "Name" e.Node.ChildNodes.DataSource = CreateHierarchichal(dTable, IDFieldName) e.Node.ChildNodes.DataBind() End If End Sub End Class [/code]
Link Posted: 21-Feb-2008 20:58
[quote="a222493"]However, when I let this run past level 1 (two levels) IE hangs.  

What do you man? Does it raise some javascript error?

[quote="a222493"]Is there a limit to how many nodes the tree control can contain?

No limit. Just in case when you have thousands of nodes, then it will take much time from IE to render all the HTML . In this case the populate-on-demand approach should be used. It will be quite easy to convert your code for this. Just set node.PopulateNodesOnDemand to True for every node that is supposed to have child nodes, and move the mClientTreeFTV_NodeDataBound code to a FlyTreeView.PopulateNodes handler. So the code will be called every time when a node is expanded at client-side.  And only required nodes will be loaded into treeview.

[quote="a222493"]Any thoughts?

It looks like you're using external references to data, so I cannot debug it locally.