This is a migrated thread and some comments may be shown as answers.

[Solved] Hierarchichal Grid EntityDataSource - Detailview filtering issue

2 Answers 77 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Michael
Top achievements
Rank 1
Michael asked on 11 Apr 2013, 12:24 PM
Hi,

I'm having a problem with hierarchical datagrid using EntityDataSource .  Hopefully its something very obvious that I've done wrong with this but I can't seem to find the issue so far. 

I have used this demo as the basis for a hierarchical grid below and substituted in my own EntityDataSource datasources as required.
http://demos.telerik.com/aspnet-ajax/grid/examples/hierarchy/declarativerelations/defaultcs.aspx

Also I've been looking at this
http://www.telerik.com/help/aspnet-ajax/grid-binding-to-declarative-datasource-controls.html

The two entity datasources are effectively doctors referrals and any associated attached files.  The referrals table is linked to the attachments table by foreign key (0,1 to many).  The basic flow of operation should be that a referral can be created without any attachments.  Attachments can be added to a referral at time of creation or at a later point. 

Each attachment has a Referralid field which relates to the id field of the Referral table.

So based on this the master table should be.

                <MasterTableView DataSourceID="EntityDataSourceReferrals" DataKeyNames="ID" AllowMultiColumnSorting="True">

The detailsview table should be related based on the below, Mastertable id is related to the REFERRALID of the attachment table (detailsview).

                            <ParentTableRelation>
                                <telerik:GridRelationFields DetailKeyField="REFERRALID" MasterKeyField="ID">
                                </telerik:GridRelationFields>
                            </ParentTableRelation>

When I run the below code I get a result where the referrals show all attachments instead of showing only those attached to the referrals  .

(Incorrect as Referral 1 has one attachment, referral 2 has no attachments)
Referral 1
 ...............=> Attachment (Referralid 1)
Referral  2
............... => Attachment (Referralid 1)

Whereas the correct result should be

Referral 1
 ...............=> Attachment (Referralid 1)
Referral  2
............... => No attachments

Any pointers as to where I'm going wrong here would be welcome.

Thanks.

<%@ Page Language="c#" CodeBehind="testdetailsview.aspx.cs" Inherits="mWebPortal.test"%>
  
<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
    <head>
        <title>Declarative relations in hierarchical ASP.NET Grid | RadGrid Demo</title>
    </head>
    <body>
        <form id="form1a" runat="server">
            <telerik:RadScriptManager runat="server" ID="RadScriptManager1" />
            <telerik:RadSkinManager ID="QsfSkinManager" runat="server" ShowChooser="true" />
            <telerik:RadFormDecorator ID="QsfFromDecorator" runat="server" DecoratedControls="All" EnableRoundedCorners="false" />
            <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
                <AjaxSettings>
                    <telerik:AjaxSetting AjaxControlID="RadGrid1">
                        <UpdatedControls>
                            <telerik:AjaxUpdatedControl ControlID="RadGrid1"></telerik:AjaxUpdatedControl>
                        </UpdatedControls>
                    </telerik:AjaxSetting>
                </AjaxSettings>
            </telerik:RadAjaxManager>
            <telerik:RadGrid ID="RadGrid1" ShowStatusBar="True"
                             DataSourceID="EntityDataSourceReferrals" runat="server" PageSize="7"
                             AllowSorting="True" AllowPaging="True" GridLines="None" CellSpacing="0">
                <PagerStyle Mode="NumericPages"></PagerStyle>
                <MasterTableView DataSourceID="EntityDataSourceReferrals" DataKeyNames="ID" AllowMultiColumnSorting="True">
                    <DetailTables>
                        <telerik:GridTableView DataKeyNames="REFERRALID" DataSourceID="EntityDataSourceRefAttachments" Width="100%"
                                               runat="server">
                            <ParentTableRelation>
                                <telerik:GridRelationFields DetailKeyField="REFERRALID" MasterKeyField="ID">
                                </telerik:GridRelationFields>
                            </ParentTableRelation>
                        </telerik:GridTableView>
                    </DetailTables>
                </MasterTableView>
            </telerik:RadGrid>
            <asp:EntityDataSource ID="EntityDataSourceReferrals" runat="server"
                ConnectionString="name=RefEntities"
                DefaultContainerName="RefEntities"
                EnableFlattening="False"
                EntitySetName="Referrals">
            </asp:EntityDataSource>
            <asp:EntityDataSource ID="EntityDataSourceRefAttachments" runat="server"
                ConnectionString="name=RefEntities"
                DefaultContainerName="RefEntities"
                EnableFlattening="False"
                EntitySetName="ReferralAttachments"
                AutoGenerateWhereClause="True">
            </asp:EntityDataSource>
        </form>
    </body>
</html>

2 Answers, 1 is accepted

Sort by
0
Accepted
Antonio Stoilkov
Telerik team
answered on 16 Apr 2013, 07:44 AM
Hi Michael,

In order to achieve your scenario you will need to specify a Where clause for the second EntityDataSourceReferrals EntityDataSource. This is required because the data source control could not determine which results to return. RadGrid automatically passes the parent key value to the datasource. Additionally, you could take a look at the example shown below.
<asp:EntityDataSource ID="EntityDataSourceRefAttachments" runat="server"
    ConnectionString="name=RefEntities"
    DefaultContainerName="RefEntities"
    EnableFlattening="False"
    EntitySetName="ReferralAttachments"
    AutoGenerateWhereClause="False" Where="it.[REFERRALID] = @ID">
    <WhereParameters>
        <asp:Parameter Name="ID" Type="Int32" />
    </WhereParameters>
</asp:EntityDataSource>

Kind regards,
Antonio Stoilkov
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Michael
Top achievements
Rank 1
answered on 16 Apr 2013, 02:53 PM
Hi Antonio, thanks for taking the time to help me with this.

As it happens I spotted the sameerror this morning after I was directed to the below article by another post on the forum

http://www.asp.net/web-forms/tutorials/getting-started-with-ef/the-entity-framework-and-aspnet-getting-started-part-3

This pointed me towards using this ControlParameter solution below and that as you mentioned because I hadn't specified which records to return.  I'm including it in case its of use to anyone looking at this query in the future.

<asp:EntityDataSource ID="EntityDataSourceRefAttachments" runat="server"
    ConnectionString="name=RefEntities"
    DefaultContainerName="RefEntities"
    EnableFlattening="False"
    EntitySetName="ReferralAttachments"
                EntitySetName="ReferralAttachments" EntityTypeFilter="ReferralAttachment" AutoGenerateWhereClause="True" Select="" Where="">
                <WhereParameters>
                    <asp:ControlParameter ControlID="RadGrid1" Name="REFERRALID" PropertyName="SelectedValue" Type="Int32" />
                </WhereParameters>
</asp:EntityDataSource>


I will take another look at the above based on your solution as it may be more appropriate though.

Thanks again.
Tags
Grid
Asked by
Michael
Top achievements
Rank 1
Answers by
Antonio Stoilkov
Telerik team
Michael
Top achievements
Rank 1
Share this question
or