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

Posted on 2008-11-17
Last Modified: 2012-05-05
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

Question by:satinderp_singh
    1 Comment
    LVL 18

    Accepted Solution


    "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?

    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    Join & Write a Comment

    Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (…
    Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…

    732 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now