access parent repeater DocumentName from child repeater

kyle shapiro asked on October 15, 2018 05:34

I have tried for so many hours to solve this one, I really need your help devnet! I have 3 tiers of nested repeaters. At the top, document repeater, let's call it "DR1". Within DR1's transformation there is another document repeater, DR2. Within DR2's transformation there's a query repeater, QR3. In QR3's transformation, I want to grab DR1's DocumentName. In DR2's transformation I was able to grab DR1's DocumentName using the following code.

<script runat="server">
protected override void OnInit(EventArgs e)
{
  base.OnInit(e);
  IDataItemContainer cont = this.Parent as IDataItemContainer;
  System.Data.DataRowView drv = (System.Data.DataRowView)cont.DataItem as System.Data.DataRowView;

  string parentDocName = ValidationHelper.GetString(drv["DocumentName"], "");
  parentDocName = parentDocName.Replace("'", "''");

  QR3.WhereCondition = "where f.parentDocName = '" + parentDocName + "'";
}
</script>

Simply specifying more parents doesn't do it. this.Parent.Parent.Parent etc. I tried all numbers of parents. I have tried so many things to try and reach DR1's DocumentName from QR3, but it's all unorganized comments in the code now, I couldn't describe it all well here. I tried working with IDataItemContainer, CMS.DocumentEngine.Web.UI.CMSRepeater, System.Web.UI.WebControls.RepeaterItem, DataItem, and Row[0]. I'm totally lost at this point. Hopefully one of you can help. It would be greatly appreciated! Thank you.

Recent Answers


Juraj Ondrus answered on October 15, 2018 08:13

Hi Kyle,
Have you tried using hierarchical transformations and hierarchical viewer (or other supported viewers)? Nested repeaters is an old approach and not very performance friendly.
In this case, the nested repeater gets the data from its parent. So the 2 level deep nested repeater does not have information about the grand-parent repeater. In this case, you would need to get to the direct parent repeater's data collection and based on this assume what are its parent's data - and this can get bit dirty.
I am not sure what your exact goal is so I would recommend checking the hierarchical transformation option to see if it will fit your needs.

0 votesVote for this answer Mark as a Correct answer

kyle shapiro answered on October 15, 2018 18:36

Hi Juraj, Thank you for your response. That's a good idea, and I agree that a hierarchical transformation would help clean up my solution and provide better performance. However I realize I had made a mistake in my question. I actually have never been able to successfully call a parent's DocumentName. I am able to get the DocumentName of the document where that query lives, Eval("DocumentName"), but not the parent of the current document. So even if I have a single Hierarchical viewer replacing my DR1 and DR2, I still don't know how to grab the tier0 and tier1 DocumentNames from the Hierarchical viewer to pass to the where condition of my QR3 that is nested in tier1 transformation of Hierarchical viewer. Or alternatively is there a way to set a public variable at the highest level of control and have it visible to the deeper tiers of controls? Thank you.

0 votesVote for this answer Mark as a Correct answer

Peter Mogilnitski answered on October 15, 2018 23:04

Can you give us a scenario? I am pretty sure you it should be one SQL query.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.