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 ONGO
SET QUOTED_IDENTIFIER ONGO
SET ANSI_PADDING ONGO
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 OFFGO
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', NULLINSERT dbo.Emp SELECT 2, 'Vice President', 1INSERT dbo.Emp SELECT 3, 'CEO', 2INSERT dbo.Emp SELECT 4, 'CTO', 2INSERT dbo.Emp SELECT 5, 'Group Project Manager', 4INSERT dbo.Emp SELECT 6, 'Project Manager 1', 5INSERT dbo.Emp SELECT 7, 'Project Manager 2', 5INSERT dbo.Emp SELECT 8, 'Team Leader 1', 6INSERT dbo.Emp SELECT 9, 'Software Engineer 1', 8INSERT dbo.Emp SELECT 10, 'Software Engineer 2', 8INSERT dbo.Emp SELECT 11, 'Test Lead 1', 6INSERT dbo.Emp SELECT 12, 'Tester 1', 11INSERT dbo.Emp SELECT 13, 'Tester 2', 11INSERT dbo.Emp SELECT 14, 'Team Leader 2', 7INSERT dbo.Emp SELECT 15, 'Software Engineer 3', 14INSERT dbo.Emp SELECT 16, 'Software Engineer 4', 14INSERT dbo.Emp SELECT 17, 'Test Lead 2', 7INSERT dbo.Emp SELECT 18, 'Tester 3', 17INSERT dbo.Emp SELECT 19, 'Tester 4', 17INSERT dbo.Emp SELECT 20, 'Tester 5', 17GO
Hi RBonser,
You should switch the childColumn and parentColumn in your DataRelation:
ParentColumn=”EmpID”, ChildColumn=”MgrID”.
Let me know if this doesn’t work in your scenario.
Regards,
Lyuba
Developer Support Engineer
Infragistics
www.infragistics.com/support
I have the same problem with almost the same case where i need to show which employee is reporting to which manager.
I have the parent and child column set correctly but still i am not able to see anything is the grid. I even followed this article but still couldn't figure out what's wrong
http://help.infragistics.com/Help/NetAdvantage/ASPNET/2010.1/CLR3.5/html/WebHierarchicalDataGrid_Binding_to_Self-Related_Data.html
The moment i add multiple dataviews even having the same dataset as Datasource to the dataview, the data comes up but this gives me wrong result as all the records are shown in the grid which is expected as i am giving the same datasource to all the views
FYI....i have self realted data in a dataset and i am binding the grid in the control INIT even in the code behind.
Appreciate any help.