1

内部 OnItemDataBound 事件(itemtype)应该被命中两次,因为这里我有 2 个孩子。但无论我尝试什么,它都只被击中一次。有什么想法吗?

数据结构:父A

儿童 X Y

前端:

<asp:Repeater ID="ParentRepeater" runat="server" OnItemDataBound="ItemBound">
    <ItemTemplate>
        <!-- Repeated data -->
        <asp:Repeater ID="ChildRepeater" runat="server" OnItemDataBound="InnerItemBound">
            <ItemTemplate>
                <asp:HiddenField ID="hdxyz" runat="server" Value="false"/>
            </ItemTemplate>
        </asp:Repeater>
    </ItemTemplate>
</asp:Repeater>

后端:

 protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            ParentRepeater.DataSource = ...;
            ParentRepeater.DataBind();
        }
    }
    protected void ItemBound(object sender, RepeaterItemEventArgs args)
    {
        if (args.Item.ItemType == ListItemType.Item)
        {
            Repeater childRepeater = (Repeater)args.Item.FindControl("ChildRepeater");
            childRepeater.DataSource = ...;
            childRepeater.DataBind();
        }
    }


protected void InnerItemDataBound(object sender, RepeaterItemEventArgs e)
{

  if (e.Item.ItemType == ListItemType.Item)
  {
    //Should be hit twice, as here I have 2 children. 
    //But whatever I try, it only hit once.
    bindHiddenFieldInRepeater(e, "hdxyz", "hdEventID");

    return;
  }
}
4

1 回答 1

2

我猜我有 3 个项目,该事件将被触发两次,而不是三次。

尝试if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)

于 2012-04-05T16:20:22.633 回答