Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
285
Generate TreeView from 1 table
posted

Hallo, I want to generate my treeview base on the data in my table, for example i have a table TreeStructure that contain

ID -> auto_inc

PARENT_ID -> int

NAME -> character

 

ID is the primary key, PARENT_ID contains ID of it's parent and NAME is the text I want to display

I want to know is there any way i can generate this data into structured treeview automatically? because before this I do it manually with recursive.

Data Sample ( ID / PARENT_ID / NAME )

1 / 0 / IT ,  2 / 0 / SUPPORT , 3 / 0 / SALES

4 / 1 / DEVELOPER , 4 / 1 / NETWORK , 5 / 2 / EDP

 tree result :

- IT

---- DEVELOPER

---- NETWORK

- SUPPORT

----EDP

- HRD

 

thx before :)

Parents
No Data
Reply
  • 28464
    Verified Answer
    posted

    Hello,

    There are various ways to proceed with binding from a single self-referencing table with ID -> ParentID relation. Recursion is one of them, but there are also easier ways to do it. For example, you can use the Levels collection of the tree to denote the relation - there is a great article describing just that here:

    http://devcenter.infragistics.com/Support/KnowledgeBaseArticle.aspx?ArticleID=10087

    Another great way to do that, is to use our new WebHierarchicalDataSource control, which lets you create hierarchical relation with a single self-referencing table. We have a nice example that shows that here:

    http://samples.infragistics.com/2008.2/webfeaturebrowser/default.htm

    (just select the WebHierarchicalDataSource -> Self-Refrencing example from the navigational menu on the left) - full source code is provided there as well, e.g.

     <ignav:UltraWebTree ID="UltraWebTree1" runat="server" DataSourceID="WebHierarchicalDataSource1"
                            DefaultImage="" HoverClass="" Indentation="20"
                            StyleSetName="LucidDream" BackColor="#FCFCFC" BorderColor="#E2F2FC"
                            BorderStyle="Solid" BorderWidth="1px"
                            Width="250px" EnableAppStyling="True" ExpandOnClick="True"
                        SingleBranchExpand="True" InitialExpandDepth="2"  >
                        <DataBindings>
                            <ignav:NodeBinding DataMember="AccessDataSource1_DefaultView"
                                TextField="LastName" />
                        </DataBindings>
                    </ignav:UltraWebTree>          
       
       
        <aikido:WebHierarchicalDataSource ID="WebHierarchicalDataSource1" runat="server">
            <DataRelations>
                <aikido:DataRelation ChildColumns="ReportsTo"
                    ChildDataViewID="AccessDataSource1_DefaultView" ParentColumns="EmployeeID"
                    ParentDataViewID="AccessDataSource1_DefaultView" />
            </DataRelations>
            <DataViews>
                <aikido:DataView ID="AccessDataSource1_DefaultView" DataMember="DefaultView"
                    DataSourceID="AccessDataSource1" />
            </DataViews>
        </aikido:WebHierarchicalDataSource>

        <asp:AccessDataSource ID="AccessDataSource1" runat="server"
            DataFile="~/App_Data/Nwind.mdb"
            SelectCommand="SELECT [EmployeeID], [LastName], [FirstName], [ReportsTo] FROM [Employees]"></asp:AccessDataSource>

    Hope this helps. 

Children