Deeptechtons
Deeptechtons

Reputation: 11125

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>[email protected]</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>[email protected]</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>[email protected]</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>[email protected]</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>[email protected]</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

Upvotes: 1

Views: 1723

Answers (3)

esims
esims

Reputation: 420

It took me hours to figure out that the name of the relation matters: two node names separated by an underscore. I had read several times that the relation was created automatically, so I didn't mind.

Upvotes: 0

Farzin Zaker
Farzin Zaker

Reputation: 3606

I think the problem is because your dataset structure is flat. this structure of repeater needs to have a list of staffs in company entity. xml should look like :

<BusinessList>
  <Company>
    <!--Other Properties-->
    <Staffs>
      <!--Staff List-->
      <Staff>
      </Staff>
      <Staff>
      </Staff>
    </Staffs>
  </Company>
</BusinessList>

Upvotes: 1

Guvante
Guvante

Reputation: 19203

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.

Upvotes: 1

Related Questions