innner OnItemDataBound事件(itemtype)应该被击中两次,因为这里有2个孩子。 但无论我尝试什么,它只会被击中一次。有什么想法吗?
数据结构: 亲 甲
儿童 X ÿ
前端:
<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;
}
}
答案 0 :(得分:2)
我猜我已经有3件物品,事件将被解雇两次,而不是三次。
尝试if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)