Nested Repeater Not Working The relation is not parented to the table to which this DataView points.

Hi All,

I have got a nested repeater within another repeater and I am getting the following error mesage .

Server Error in '/' Application.

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

I could not find what is wrong . attached is the code snippet. any help will be apreciated..

This is the .aspx file 
<%@ Page Language="C#" MasterPageFile="~/MideaMaster.master" AutoEventWireup="true" CodeFile="ProductType.aspx.cs" Inherits="ProductType" Title="Untitled Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="MideaContentBody" Runat="Server">
 <div id = "ProductTypeMainImage">
<asp:Repeater ID="DepartmentRepeat" runat="server" OnItemDataBound="Department_DataBound" >
 <ItemTemplate><li><strong><%# DataBinder.Eval(Container.DataItem, "ProductId") %> - <%# DataBinder.Eval(Container.DataItem, "ProductName") %></strong></li>
      <asp:Repeater ID="CategoryRepeat" runat="server" >
  <ItemTemplate><li><%# DataBinder.Eval(Container.DataItem, "ProductId") %> - <%# DataBinder.Eval(Container.DataItem, "Subcategory") %></li></ItemTemplate>
And this is my code behind file 
public partial class ProductType : System.Web.UI.Page
    SqlConnection MideaConnection;
    protected void Page_Load(object sender, EventArgs e)
        MideaConnection = new SqlConnection("Data Source=ACCPAC\\CASTEL;Initial Catalog=Midea;uid = WebLogin;pwd=cepre#dae#");
        SqlDataAdapter MideaDataAdapter = new SqlDataAdapter();
        DataSet MideaDataSet = new DataSet();
        SqlCommand MideaProductCommand = new SqlCommand();
        MideaProductCommand.Connection = MideaConnection;
        MideaDataAdapter.SelectCommand = MideaProductCommand;
        MideaProductCommand.CommandText = @" Select * from Product";
        MideaDataAdapter.Fill(MideaDataSet, "Product");
        DepartmentRepeat.DataSource = MideaDataSet.Tables["Product"];
        SqlCommand MideaSubcategoryCommand = new SqlCommand();
        MideaSubcategoryCommand.Connection = MideaConnection;
        MideaDataAdapter.SelectCommand = MideaSubcategoryCommand;
        MideaSubcategoryCommand.CommandText = @"Select distinct ProductID,SubCategory from Models";
        MideaDataAdapter.Fill(MideaDataSet, "SubCategory");
        DataRelation drv = new DataRelation("myRelation", MideaDataSet.Tables["Product"].Columns["ProductId"], MideaDataSet.Tables["SubCategory"].Columns["ProductId"]);
        //Dim rpt as repeater = Ctype(DepartRepeat.Items(0).findcontrol("CategoryRepeat"),Repeater)
    protected void Department_DataBound(object sender, RepeaterItemEventArgs e)
        RepeaterItem item = e.Item;
        if ((item.ItemType == ListItemType.Item) || (item.ItemType == ListItemType.AlternatingItem))
            Repeater r = (Repeater)item.FindControl("CategoryRepeat");
            DataRowView drv = (DataRowView)item.DataItem;
            r.DataSource = drv.CreateChildView("myRelation");

Open in new window

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.


"Problem Solved, If anybody is interested to know what went wrong, when using nested items in .Net with a data relation,you need to make sure you create the relation explicitly before you create your view and before you bind to the repeater, otherwise the relation will mysteriously appear to be active but will not be bound."

Does that help?

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.