?
Solved

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

Posted on 2008-11-17
2
Medium Priority
?
1,645 Views
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" >
<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

0
Comment
Question by:satinderp_singh
1 Comment
 
LVL 18

Accepted Solution

by:
ChetOS82 earned 2000 total points
ID: 22987238
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

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses
Course of the Month13 days, 19 hours left to enroll

807 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