【问题标题】:Nested Repeaters - access value from parent row in Footer嵌套中继器 - 从页脚中的父行访问值
【发布时间】:2012-02-03 08:57:53
【问题描述】:

我有一个嵌套中继器的情况,其中子中继器嵌套在父中继器的ItemTemplate 中。父级的 DataSource 是 Dictionary<String, List<XYZ>>。 在父中继器的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. 事件触发的顺序是否如下:

一个。 Parent_ItemDataBound 用于Dictionary&lt;Key, List&lt;XYZ&gt;&gt; 的第 1 行

我。 Child_ItemDataBound 对于每个父中继器第 1 行的子行

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

b. Parent_ItemDataBound 用于Dictionary&lt;Key, List&lt;XYZ&gt;&gt; 的第 2 行

我。 Child_ItemDataBound 对于每个父中继器第 2 行的子行

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

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

【问题讨论】:

    标签: asp.net repeater


    【解决方案1】:

    以下是您问题的答案:

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

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

    2. 顺序正确。

    希望有帮助

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-10-20
      • 2010-11-12
      • 2023-03-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多