内部 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;
}
}