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
915
Problem with Self Referencing Table as Source
posted

I have created a WebHierarchialDataSource that uses a LinqDataSource which selects its data from a self referencing SQL Server table.

I have confirmed that the LinqDataSource is indeed brining back the data from the table and I have my relations setup property, but when I bind the WebHierarchialGrid it keeps telling me there are no rows to display.  I cannot figure out why.

I even tried this with a SqlDataSource and get the same results.

Here is my code for the webpage:

<ig:WebHierarchicalDataGrid ID="whdg1" runat="server" DataSourceID="WebHierarchicalDataSource2"
    AutoGenerateColumns="False" AutoGenerateBands="False" Height="350px" Width="99.7%"
    DataKeyFields="MgrID"
    ExpandableAreaCssClass="ighg_FeatureBrowserExpandableArea"
    DataMember="LinqDataSource2_DefaultView" IsSelfReference="True"
    Key="LinqDataSource2_DefaultView">
    <ExpandCollapseAnimation SlideCloseDirection="Auto" SlideCloseDuration="300" SlideOpenDirection="Auto"
        SlideOpenDuration="300" />
    <Columns>
        <ig:BoundDataField DataFieldName="EmpID" Key="EmpID">
            <Header Text="EmpID" />
        </ig:BoundDataField>
        <ig:BoundDataField DataFieldName="EmpName" Key="EmpName">
            <Header Text="EmpName" />
        </ig:BoundDataField>
        <ig:BoundDataField DataFieldName="MgrID" Key="MgrID">
            <Header Text="MgrID" />
        </ig:BoundDataField>
    </Columns>
    <EmptyRowsTemplate>
        <div style="text-align: center;">
            <br />
            <br />
            <img src="attention.png" align="middle" alt="Attention..." />
            No Destinations Found.
        </div>
    </EmptyRowsTemplate>
    <ErrorTemplate>
        <div style="text-align: center;">
            <img src="error.png" align="middle" alt="Error..." />
            An error has occurred! Please contact support.
        </div>
    </ErrorTemplate>
</ig:WebHierarchicalDataGrid>
<asp:LinqDataSource ID="LinqDataSource2" runat="server"
    ContextTypeName="TestHTMLEditor.EmpDataContext"
    Select="new (EmpID, EmpName, MgrID)" TableName="Emps">
</asp:LinqDataSource>
<ig:WebHierarchicalDataSource ID="WebHierarchicalDataSource2" runat="server">
    <DataViews>
        <ig:DataView ID="LinqDataSource2_DefaultView" DataMember="DefaultView"
            DataSourceID="LinqDataSource2" />
    </DataViews>
    <DataRelations>
        <ig:DataRelation ChildColumns="EmpID"
            ChildDataViewID="LinqDataSource2_DefaultView" ParentColumns="MgrID"
            ParentDataViewID="LinqDataSource2_DefaultView" />
    </DataRelations>
</ig:WebHierarchicalDataSource>

Here is the code to create the table I am using:

USE [TestDB]
GO

/****** Object:  Table [dbo].[Emp]    Script Date: 10/21/2010 15:24:35 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

SET ANSI_PADDING ON
GO

CREATE TABLE [dbo].[Emp](
 [EmpID] [int] NOT NULL,
 [EmpName] [varchar](30) NULL,
 [MgrID] [int] NULL,
PRIMARY KEY CLUSTERED
(
 [EmpID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

SET ANSI_PADDING OFF
GO

ALTER TABLE [dbo].[Emp]  WITH CHECK ADD FOREIGN KEY([MgrID])
REFERENCES [dbo].[Emp] ([EmpID])
GO

Here is code to insert data in to the table:

INSERT dbo.Emp SELECT 1, 'President', NULL
INSERT dbo.Emp SELECT 2, 'Vice President', 1
INSERT dbo.Emp SELECT 3, 'CEO', 2
INSERT dbo.Emp SELECT 4, 'CTO', 2
INSERT dbo.Emp SELECT 5, 'Group Project Manager', 4
INSERT dbo.Emp SELECT 6, 'Project Manager 1', 5
INSERT dbo.Emp SELECT 7, 'Project Manager 2', 5
INSERT dbo.Emp SELECT 8, 'Team Leader 1', 6
INSERT dbo.Emp SELECT 9, 'Software Engineer 1', 8
INSERT dbo.Emp SELECT 10, 'Software Engineer 2', 8
INSERT dbo.Emp SELECT 11, 'Test Lead 1', 6
INSERT dbo.Emp SELECT 12, 'Tester 1', 11
INSERT dbo.Emp SELECT 13, 'Tester 2', 11
INSERT dbo.Emp SELECT 14, 'Team Leader 2', 7
INSERT dbo.Emp SELECT 15, 'Software Engineer 3', 14
INSERT dbo.Emp SELECT 16, 'Software Engineer 4', 14
INSERT dbo.Emp SELECT 17, 'Test Lead 2', 7
INSERT dbo.Emp SELECT 18, 'Tester 3', 17
INSERT dbo.Emp SELECT 19, 'Tester 4', 17
INSERT dbo.Emp SELECT 20, 'Tester 5', 17
GO

Parents
No Data
Reply Children