satinderp_singh
asked on
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..
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();
}
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.