How to Bind 3 Level Nested Repeaters in ASP.NET?
-
Tuesday, March 06, 2012 4:08 PM
i m creating a aspx page in Visual Studio 2010.
i have used 2 level nested repeaters and they are working good.
but now i want to use 3 level nested repeater and it show this error.
"The relation is not parented to the table to which this DataView points."
i have searched alot but cant fix this :( please help me
here is the html of my page
<div> <asp:Repeater ID="rptAllCatagories" runat="server" OnItemDataBound="rptAllCatagories_ItemDataBound"> <ItemTemplate> <asp:Label ID="AllCatagoryTitle" runat="server"> <%#Eval("CategoryName")%> </asp:Label> <asp:Repeater ID="rptProductsList" runat="server" OnItemDataBound="rptProductsList_ItemDataBound"> <ItemTemplate> <table> <tr> <td align="left"> <asp:Label ID="Label1" runat="server"> <%#Eval("ProductName")%> </asp:Label> </td> <td style="width: 140px"> <asp:Repeater ID="rptPriceList" runat="server"> <ItemTemplate> <h6> <asp:Label ID="Label3" runat="server" Text="Price:"></asp:Label>: <%#Eval("Price")%> <br /> </h6> </ItemTemplate> </asp:Repeater> </td> </tr> </table> </ItemTemplate> </asp:Repeater> </ItemTemplate> </asp:Repeater> </div>
and here is the code
protected void Page_Load(object sender, EventArgs e) { try { if (!IsPostBack) { GetProductsByCatagoryALL(0); } } catch (Exception) { throw; } } void GetProductsByCatagoryALL(int id) { try { DataSet resultSet = new DataSet("resultSet"); // Filling dataset for Categories DataSet dsCategoriesList = new DataSet(); dsCategoriesList = Database.RunSPReturnDataSet("sp_CatagoriesList", string.Empty, null); if (dsCategoriesList.Tables[0].Rows.Count > 0) { DataTable dtCatagory = new DataTable("Catagory"); dtCatagory = dsCategoriesList.Tables[0]; dtCatagory.TableName = "Catagory"; resultSet.Tables.Add(dtCatagory.Copy()); // Filling dataset for Products DataSet dsProductsList = new DataSet(); dsProductsList = Database.RunSPReturnDataSet("sp_ProductsByCatagoryAll", string.Empty, null); if (dsProductsList.Tables[0].Rows.Count > 0) { DataTable dtProduct = new DataTable("Product"); dtProduct = dsProductsList.Tables[0]; dtProduct.TableName = "Product"; resultSet.Tables.Add(dtProduct.Copy()); resultSet.Relations.Add(new DataRelation("CatagoryofProduct", resultSet.Tables["Catagory"].Columns["CategoryId"], resultSet.Tables["Product"].Columns["CategoryId"])); resultSet.Relations[0].Nested = true; // Filling dataset for Price DataSet dsPriceList = new DataSet(); dsPriceList = Database.RunSPReturnDataSet("sp_PriceByProduct", string.Empty, null); if (dsPriceList.Tables[0].Rows.Count > 0) { DataTable dtPrice = new DataTable("Price"); dtPrice = dsPriceList.Tables[0]; dtPrice.TableName = "Price"; resultSet.Tables.Add(dtPrice.Copy()); resultSet.Relations.Add(new DataRelation("PriceofProduct", resultSet.Tables["Product"].Columns["ProductID"], resultSet.Tables["Price"].Columns["ProductID"])); resultSet.Relations[1].Nested = true; } //binding the main repeater rptAllCatagories.DataSource = dsCategoriesList.Tables[0]; rptAllCatagories.DataBind(); } } } catch (Exception) { throw; } } protected DataView GetChildRelation(object dataItem, string relation) { DataRowView drv = dataItem as DataRowView; if (drv != null) return drv.CreateChildView(relation); else return null; } protected void rptProductsList_ItemDataBound(object sender, System.Web.UI.WebControls.RepeaterItemEventArgs e) { if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { Repeater tempRptPrice = (Repeater)e.Item.FindControl("rptPriceList"); if (tempRptPrice != null) { tempRptPrice.DataSource = GetChildRelation(e.Item.DataItem, "PriceofProduct"); tempRptPrice.DataBind(); } } } protected void rptAllCatagories_ItemDataBound(object sender, System.Web.UI.WebControls.RepeaterItemEventArgs e) { if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { Repeater tempRptProduct = (Repeater)e.Item.FindControl("rptProductsList"); if (tempRptProduct != null) { tempRptProduct.DataSource = GetChildRelation(e.Item.DataItem, "CatagoryofProduct"); tempRptProduct.DataBind(); } } }
this error comes in this line.
drv.CreateChildView(relation);
please guide me.
Thanks in Advance,
With Regards,
Muhammad Luqman
Muhammad Luqman
- Moved by Vicky Song Wednesday, March 07, 2012 7:21 AM (From:Visual Studio Database Development Tools (Formerly "Database Edition Forum"))
All Replies
-
Wednesday, March 07, 2012 7:21 AM
Hello Muhammad,
I am sorry that here is not the correct forum for you to deal with your issue. Please reopen one new case on the ASP.NET forum here:
Thanks.
Vicky Song [MSFT]
MSDN Community Support | Feedback to us

