asp.netdata-bindinguser-controlsrepeater

The relation is not parented to the table to which this DataView points


<BusinessList>
  <Company>
    <CompanyName>StackOverflow</CompanyName>
    <Desc>FAQ Q & A Site</Desc>
    <Email>dummy@dummy.com</Email>
    <Mobile>123456</Mobile>
    <Phone>123456</Phone>
    <City>florida</City>
    <ZipCode>620020</ZipCode>
    <Country>USA</Country>
    <State>FL</State>
    <Image>a.png</Image>
  </Company>
  <Staff>
    <FirstName>A</FirstName>
    <Qualification>Bachelor in Engineering</Qualification>
    <Stories>Highly enthusiastic and energetic programmer will surely work with him again - Jane</Stories>
    <Designation>Chief Engineer</Designation>
    <Email>dummy@dummy.com</Email>
    <ContactNo>123456</ContactNo>
    <Fax>56565656</Fax>
    <Image>1.png</Image>
  </Staff>
  <Staff>
    <FirstName>B</FirstName>
    <Qualification>Bachelor in Engineering</Qualification>
    <Stories>Highly enthusiastic and energetic programmer will surely work with him again - Jane</Stories>
    <Designation>Team Leader</Designation>
    <Email>dummy@dummy.com</Email>
    <ContactNo>123456</ContactNo>
    <Fax>5757575</Fax>
    <Image>2.png</Image>
  </Staff>
  <Staff>
    <FirstName>C</FirstName>
    <Qualification>Bachelor in Engineering</Qualification>
    <Stories>Highly enthusiastic and energetic programmer will surely work with him again - Jane</Stories>
    <Designation>Programmer</Designation>
    <Email>dummy@dummy.com</Email>
    <ContactNo>123456</ContactNo>
    <Fax>565656</Fax>
    <Image>3.png</Image>
  </Staff>
  <Staff>
    <FirstName>D</FirstName>
    <Qualification>Bachelor in Engineering</Qualification>
    <Stories>Highly enthusiastic and energetic programmer will surely work with him again - Jane</Stories>
    <Designation>Developer</Designation>
    <Email>dummy@dummy.com</Email>
    <ContactNo>123456</ContactNo>
    <Fax>1231231234</Fax>
    <Image>4.png</Image>
  </Staff>
</BusinessList>

Above is my xml inout file for the Dataset, which i read with DataSet.ReadXml() method.However i get a error when i databind with nested repeater like below.

                        <asp:Repeater runat="server" id="rptrCompany">
                            <HeaderTemplate>
                                Staff in company
                            </HeaderTemplate>
                            <ItemTemplate>
                                Company Details:
                                <%# Eval("CompanyName") %>
                                .. blahblahblah Staff Details
                                <asp:Repeater runat="server" id="rptrStaff" datasource='<%# ((DataRowView)Container.DataItem).CreateChildView("BusinessList_Staff") %>'>
                                    <HeaderTemplate>
                                        Staff List
                                    </HeaderTemplate>
                                    <ItemTemplate>
                                        <%# Eval("FirstName") %>
                                        ..blah blah blah
                                    </ItemTemplate>
                                </asp:Repeater>
                            </ItemTemplate>
                        </asp:Repeater>

blah blah blah part denoted extra fields that i databound. In the child repeater i get the error/exception The relation is not parented to the table to which this DataView points. What am i doing wrong, the relation name "BusinessList_Staff" exists when i checked the dataset[ relation is automatically created by framework for me]. Also Container.Dataitem is a datarowview which also has 'CreateChildView' method used in markup. All i do is DataBind the parent repeater in backend pageLoad like below rptrCompany.DataSource = dtTemp.Tables["Company"].DefaultView; rptrCompany.DataBind();

Please let me know what am i doing wrong


Solution

  • Could it be because the staff are not part of the Company? The only relation that could exist in your XML is an implicit relation to the Company by being after the company.

    If you have control over the XML generation you should change the <Staff> elements to be contained within the <Company>.

    Haven't databinding in this fashion in a long time, so sorry if this is not a complete solution.