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" >
<HeaderTemplate><ul></HeaderTemplate>
<FooterTemplate></ul></FooterTemplate>
 <ItemTemplate><li><strong><%# DataBinder.Eval(Container.DataItem, "ProductId") %> - <%# DataBinder.Eval(Container.DataItem, "ProductName") %></strong></li>
                
      <asp:Repeater ID="CategoryRepeat" runat="server" >
                    <HeaderTemplate><ul></HeaderTemplate>
                    <FooterTemplate></ul></FooterTemplate>
  <ItemTemplate><li><%# DataBinder.Eval(Container.DataItem, "ProductId") %> - <%# DataBinder.Eval(Container.DataItem, "Subcategory") %></li></ItemTemplate>
                </asp:Repeater>                
            
            
            
            </ItemTemplate>
        </asp:Repeater>
 
 
 
 
 
 </div>
</asp:Content>
 
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#");
        MideaConnection.Open();
        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"];
        DepartmentRepeat.DataBind();
        Page.DataBind();
        
 
        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"]);
        MideaDataSet.Relations.Add(drv);
       
 
        //MideaDataSet.Relations.Add("myRelation",MideaDataSet.Tables["Product"].Columns["ProductId"],MideaDataSet.Tables["SubCategory"].Columns["ProductId"],false);
        
 
        //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");
            r.DataBind();
 
        
        }
       
        
       
    }
}

Open in new window

satinderp_singhAsked:
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.

ChetOS82Commented:
From: http://www.experts-exchange.com/Programming/Languages/.NET/Q_20761785.html

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

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
ASP.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.