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
WebHierarchicalDataSource with self-referencing data

I am having a problem getting my self-referencing datasource set up.  I think it has something to do with the actual data that is coming back and what the WHDS is expecting.  Here's my situation: we have a middle tier solution setup that returns type Collection<Organization>.  Organization is a business object that contains 3 important fields for our application: OrganizationID, ParentOrgID, and OrganizationName.  I am trying to bind this to a WebDataTree in an Hierarchial fashion, but here's the tricky part.  A node is a root Node when its ParentOrgID is 0 OR its a root Node when its ParentOrgID is not present in the list.  This is because some of our business methods return filtered lists which may not contain Organizations with an OrganizationID of 0.  They return a small branch of the whole complete tree or several branches.

Additionally, there are a few thousand entries returned at times (obviously I want to use some sort of paging in the end).

I know the ObjectDataSource is working correct as I am able to bind it to a drop down list and if I take the DataRelation out of the WHDS, the tree binds, but not the way I want.  My only conclusion is that there is some expected format for the data in order for the DataRelation to work properly.  Thoughts?

    <ig:WebHierarchicalDataSource ID="dataSource" runat="server" RootDataViewID="View1">
            <ig:DataRelation ChildColumns="ParentOrgID" ChildDataViewID="View1" ParentColumns="OrganizationID"
                ParentDataViewID="View1" />
            <ig:DataView ID="View1" DataSourceID="allOrgsDS" />
    <asp:ObjectDataSource ID="allOrgsDS" runat="server" TypeName="MiddleTier"

  • 12025


    This seems a bit different case than the usual self referencing relationship datasources. When setting up the WebHierarhicalDataSource, it is expected you to supply the parent and child id columns which in your case would be OrganizationID and ParentOrgID. It means that if there is a ParentOrgID, then it is not a parent level item, so it will go on the lower level and will belong to the node of that organization id. 

    I would recommend you simplify the self relationship if possible, or generate the tree structure by hand while going through your collection. 


  • 280
    Verified Answer

    I have figured out the problem after getting with Infragisitics support.  I was unable to create the self-referencing relationship because the OrganizationID and ParentOrgID fields were regular INTs. As soon as I made them Nullable INTs (Nullable<int> or int?) and set the root nodes to null, it worked like a charm.

    I am working with collections of objects, not datatables and datasets.  The WebHierarchicalDataSource is designed to work with the latter, which makes sense as to why I had to make them nullable.