嵌套重复器 - 从页脚中的父行访问值

发布于 2025-01-02 06:44:50 字数 1844 浏览 1 评论 0 原文

我有一个嵌套转发器的情况,其中子转发器嵌套在父转发器的 ItemTemplate 中。父级的 DataSource 是一个 Dictionary>。 在父 Repeater 的 ItemDataBound 中,我使用完整的代码:

     protected void rptParent_ItemDataBound(object sender, RepeaterItemEventArgs e)
     {
   if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
         {
      if (e.Item.DataItem is KeyValuePair<String, List<Object>>)
            {
                pair = (KeyValuePair<String, List<XYZ>>)e.Item.DataItem;
            }

            Repeater childRepeater = e.Item.FindControl("rptChild") as Repeater;

            //bind the child repeater.
            childRepeater.ItemDataBound += new RepeaterItemEventHandler(childRepeater_ItemDataBound);
            childRepeater.DataSource = pair.Value;
            childRepeater.DataBind();
    }
}

protected void childRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Footer)
        {
    //Access the Parent row's Key value

  }
    }

有 2 个问题:

  1. 我可以在绑定父级时使用隐藏字段并将其设置为 Key 值,然后检索子级中的隐藏字段值?

  2. 事件触发的顺序是否如下:

事件触发的顺序 Dictionary> 第 1 行的 Parent_ItemDataBound

i. Child_ItemDataBound 对于父中继器第 1 行的每个子行

ii。 Child_ItemDataBound 用于子中继器的页脚

b. Dictionary> 第 2 行的 Parent_ItemDataBound

i. Child_ItemDataBound 对于父中继器第 2 行的每个子行

ii。 Child_ItemDataBound 用于子中继器的页脚

等。换句话说,每个子行的 Parent_ItemDataBound 事件之后是否会跟随 Child_ItemDataBound 事件 - 循环重复?

I have a case of nested repeaters where a child repeater is nested in the ItemTemplate of a parent repeater. The DataSource of the parent is a Dictionary<String, List<XYZ>>.
In the ItemDataBound of the parent Repeater I am using the full code:

     protected void rptParent_ItemDataBound(object sender, RepeaterItemEventArgs e)
     {
   if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
         {
      if (e.Item.DataItem is KeyValuePair<String, List<Object>>)
            {
                pair = (KeyValuePair<String, List<XYZ>>)e.Item.DataItem;
            }

            Repeater childRepeater = e.Item.FindControl("rptChild") as Repeater;

            //bind the child repeater.
            childRepeater.ItemDataBound += new RepeaterItemEventHandler(childRepeater_ItemDataBound);
            childRepeater.DataSource = pair.Value;
            childRepeater.DataBind();
    }
}

protected void childRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Footer)
        {
    //Access the Parent row's Key value

  }
    }

There are 2 questions:

  1. Can I use a hidden field while binding the parent and set it to the Key value and then retrieve the hidden field value in the child?

  2. Will the order of the events firing be as follows:

a. Parent_ItemDataBound for Row 1 of Dictionary<Key, List<XYZ>>

i. Child_ItemDataBound for each child row of Row 1 of parent repeater

ii. Child_ItemDataBound for Footer of child repeater

b. Parent_ItemDataBound for Row 2 of Dictionary<Key, List<XYZ>>

i. Child_ItemDataBound for each child row of Row 2 of parent repeater

ii. Child_ItemDataBound for Footer of child repeater

and so on. In other words, will the Parent_ItemDataBound be followed by Child_ItemDataBound events for each child row - with the cycle repeating?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

你列表最软的妹 2025-01-09 06:44:50

以下是您问题的答案:

  1. 是的,您可以访问父中继器项目控制

    var hfID = e.Item.NamingContainer.NamingContainer.FindControl("hfID") as HiddenField;

  2. 顺序正确。

希望有帮助

Here are the answers to your question:

  1. Yes, you can access parent repeater item control

    var hfID = e.Item.NamingContainer.NamingContainer.FindControl("hfID") as HiddenField;

  2. the order is correct.

Hope that helps

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文