1
innner OnItemDataBound event(itemtype)should be hit twice,as here I have 2 children。 但無論我嘗試,它只被擊中一次。有什麼想法嗎?itemtemplate in inner nested repeater can not be fired properly
數據結構: 家長 一個
兒童 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;
}
}
這真是一個很棒的提示。我應該在2小時前發佈這個問題。但爲什麼?我把控制放在itemtemplate而不是一個AlternatingItemTemplate模板中。 – ValidfroM 2012-04-05 16:23:03