2
votes

I am trying to set up a scenario with nested repeaters in which I have a multiple different categories with multiple children displayed under them. The trouble is this, the parent table and child table match on category id which returns the desired results for all tables categories but this one. For some reason In this scenario I only get back textCategory1 from table A as the header text with all of children from table b in that category on the page, I checked the sp and all three are being passed.

Parent Table A
Title Text:TextCategory1|Category:13

Title Text:TextCategory2|Category:73

Title Text:TextCategory3|Category:14

Child Table B
Title Text:childText|Category:13 |Parent Category:Null

Title Text:childText|Category:74|Parent Category:2

Title Text:childText|Category:14|Parent Category:2

This is the data relation I used and I am databinding the Master repeater to the results of the first table while the child repeater is bound in the master item databound to a datarow.createchildview of the data relation.

ds.Relations.Add(new DataRelation("Category_ID", ds.Tables[0].Columns["Category_ID"],
ds.Tables[1].Columns["Category_ID"]));

MasterRep.DataSource = ds.Tables[0];
MasterRep.DataBind();

Section in MasterRep Item DataBound:

 DataRowView drv = e.Item.DataItem as DataRowView;
 Repeater ChildRep = e.Item.FindControl("ChildRep") as Repeater;

 if (drv != null && ChildRep != null)
 {

    ChildRep.DataSource = drv.CreateChildView("Category_ID");
    ChildRep.DataBind();
 }

Can anyone suggest a reason why I would not get all three of the policy text rows from table a in this scenario?

2

2 Answers

0
votes

A few things stand out that do not make sense, and could very well be causing your problem.

(I am assuming that the child row's Parent Category is what connects the Child Rows to the Parent Rows (using the Parent Rows's Category ID). )

  1. The first item in Table B (Category 13) has a Parent Category of null. This would mean that it has no parent. Also the Category ID is the same as the Category ID of the first item in Table A.
  2. Both items 2 & 3 in Table B have a Parent Category of 2. There are no items in Table A that have this ID, effectively meaning that there is no Parent for these two child items.
  3. Item 3 in Table B has the same ID as item 3 in Table A.

Also, can you edit your answer to include the full code for the MasterRep OnItemDatabound() method? The problem might also be in there.

0
votes

It turns out the code was functioning properly but the data was not correct, once I corrected this my code functions properly. In table A every category is represented even ones with parent categories which are then matched based on category with table b. This actually functions correctly in my code using the data relation and item databound childview. I based my approach for this off of this very helpful link mikesdotnetting.com/Article/57/… but taylored it to be for many parents with many children.