访问父中继DataItem属性 [英] Access Parent Repeaters DataItem Property

查看:100
本文介绍了访问父中继DataItem属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有,有一个直放站,rptReferrals,通过实体对象的列表,转诊运行的控制。该引荐对象具有到称为回答另一个表,这是得到提交给用户的答案的列表的参考。 rptReferrals将孩子中继器,rptQuestionnaire绑定到我登录时的人,这是不连接到介绍人问题的列表对象势必。

I have a control that has a Repeater, rptReferrals, that runs through a list of Entity objects, Referrals. The Referrals object has a reference to another table called Answers, which is a list of Answers that got submitted for the user. rptReferrals will bind a child repeater, rptQuestionnaire to a List of Questions for the person I am logged in with, which is not connected to the Referrals object it is bound to.

下面是ASPX code:

Here is the aspx code:

<asp:Repeater runat="server" ID="rptReferrals" OnItemDataBound="rptReferrals_OnItemDataBound">
    <ItemTemplate>
        //some HTML for the referral object
        <asp:Repeater runat="server" ID="rptQuestionnaire" OnItemDataBound="rptQuestionnaire_OnItemDataBound">
              //some HTML for displaying questions and answers
        </asp:Repeater>
    </ItemTemplate>
 </asp:Repeater>

后端code:

protected void rptReferrals_OnItemDataBound(object sender, RepeaterItemEventArgs e)
{
    if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
    {
         //THIS IS THE ITEM THAT HAS THE LIST OF ANSWERS I NEED
         var data = e.Item.DataItem as PatientReferral;
         var rptQuestionnaire = e.Item.FindControl("rptQuestionnaire") as Repeater;
         rptQuestionnaire.DataSource = QuestionList;   
         rptQuestionnaire.DataBind();

         //QuestionList is a list of questions populated on page load.
         // I can't bind to the property of data.Answers because not
         //all questions are answered. data.Answers is only a list of 
         //the questions answered
    }
}

protected void rptQuestionnaire_OnItemDataBound(object sender, RepeaterItemEventArgs e)
{
    if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
    {
       Need to access the data.Answers object from above. HOW????
    }
}

我遇到的问题是不需要的问题清单,我需要,无论用户是否回答了或不显示所有的问题。但是,如果他们没有回答这个问题,我需要显示的答案,这是附加到rptReferrals财产。

The problem I am having is that the list of questions are not required and I need to display all the questions regardless of whether the user answered it or not. But if they did answer it, I need to display the answer, which is the property attached to rptReferrals.

如何进入我的父母中继器的DataItem的属性,任何想法?我会采取任何的答案在这一点上。

Any ideas on how to access a property of the dataitem of my parent repeater? I'll take any answer at this point.

推荐答案

您可以使用的RepeaterItem .Parent 属性$ C>控制,以您的方式工作外的RepeaterItem (因此,它的的DataItem )。

You can use the .Parent attribute of the RepeaterItem control to work your way up to the outer RepeaterItem (and, thus, its DataItem).

看起来这将工作:

protected void rptQuestionnaire_OnItemDataBound(object sender, RepeaterItemEventArgs e)
{
    if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
    {
       Repeater currentRepeater = (Repeater)sender;
       // Note that you might only need one ".Parent" here.  Or you might need
       // more, depends on your actual markup.
       var data = ((RepeaterItem)e.Item.Parent.Parent).DataItem as PatientReferral;
       // Now you have access to data.Answers from the parent Repeater
    }
}

这篇关于访问父中继DataItem属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆