Bind Child Entities from DomainDataSource RRS feed

  • Question

  • User165425137 posted

    I'm having an issue binding to child entities using the DomainDataSource control.  Here's the DomainDataSource that I've got on my page.

                                    <ria:DomainDataSource ID="CommunicationDetailsDomainDataSource" runat="server" DomainServiceTypeName="CRM.Data.Services.CrmService"
                                        EnableInsert="True" EnableUpdate="True" QueryName="GetSituationByID" OnQueried="CommunicationDetailsDomainDataSource_Queried">
                                            <asp:QueryStringParameter DbType="Int32" QueryStringField="ID" Name="ID" ConvertEmptyStringToNull="true" />

    Here's the method it's calling on my Domain Service (CrmService)

            public Situation GetSituationByID(int ID)
                return this.ObjectContext
                    .Where(s => s.ID == ID)

    And here's the metadata for my Situation entity

                #region Entity Properties
                public int ID { get; set; }
                [Required(ErrorMessage="A Category is required for filing")]
                public int SituationTypeID { get; set; }
                [Required(ErrorMessage="Please enter a short description of the Communication")]
                [Display(Prompt="Enter a short description of the Communication")]
                public string Description { get; set; }
                [Display(Name="Created Date")]
                public DateTime CreatedDate { get; set; }
                [Display(Name="Created By")]
                public string CreatedBy { get; set; }
                [Display(Name="Modified Date")]
                public DateTime ModifiedDate { get; set; }
                [Display(Name="Closed Date")]
                public Nullable<DateTime> ClosedDate { get; set; }
                #region Navigation Properties
                public EntityCollection<Correspondence> Correspondences { get; set; }
                public EntityCollection<Note> Notes { get; set; }
                public EntityCollection<Task> Tasks { get; set; }

    Here's the DetailsView that I have bound to the DomainDataSource

                                    <asp:DetailsView ID="DetailsView1" runat="server" Height="50px" Width="125px" AutoGenerateRows="False"
                                        DataKeyNames="ID" DataSourceID="CommunicationDetailsDomainDataSource">
                                            <asp:BoundField DataField="ID" HeaderText="ID" ReadOnly="True" SortExpression="ID" />
                                            <asp:BoundField DataField="SituationTypeID" HeaderText="SituationTypeID" SortExpression="SituationTypeID" />
                                            <asp:BoundField DataField="Description" HeaderText="Description" SortExpression="Description" />
                                            <asp:BoundField DataField="CreatedBy" HeaderText="CreatedBy" SortExpression="CreatedBy" />
                                            <asp:BoundField DataField="CreatedDate" HeaderText="CreatedDate" SortExpression="CreatedDate" />
                                            <asp:BoundField DataField="ModifiedDate" HeaderText="ModifiedDate" SortExpression="ModifiedDate" />
                                            <asp:BoundField DataField="ClosedDate" HeaderText="ClosedDate" SortExpression="ClosedDate" />

    And here's the grid view that I want to bind to the Correspondences collection.

                                                        <asp:GridView ID="GridView1" runat="server" 
                                                            AutoGenerateColumns="false" >
                                                                <asp:BoundField DataField="CreatedBy" HeaderText="Created By" />
                                                                <asp:BoundField DataField="CreatedDate" HeaderText="Created Date" />
                                                                <asp:BoundField DataField="Contact" HeaderText="Contact" />

    I want to bind the child GridView using the same DomainDataSource that I'm using for Situations. The only DataMember that I can access from the DomainDataSource is DefaultView. I've tried using <%# Bind() %> and dot notation and it returns that there's no property. I'm not sure why this is and need to get it figured out as the 'Contact' field there is a related entity I want to show fields from as well.

    I can do this in code behind and get it to work but I lose the ChangeSet tracking and automatic storing in ViewState that I get with the DomainDataSource.

                CrmService svc = new CrmService();
                Situation situation = svc.GetSituationByID(Convert.ToInt32(Request.QueryString["ID"]));
                GridView1.DataSource = situation.Correspondences;

    I'm at a loss for how to do this, and the documentation for the DomainDataSource in WebForms is minimal. Any help would be appreciated.

    Thanks in advance

    Friday, September 16, 2011 10:51 AM

All replies

  • User3866881 posted

    The only DataMember that I can access from the DomainDataSource is DefaultView. I've tried using <%# Bind() %> and dot notation and it returns that there's no property


    What did you write in the Bind?

    Please change to Eval instead.

    Thx again

    Saturday, September 17, 2011 10:43 PM