这是 HTML 代码:
<asp:Repeater ID="Repeater1" runat="server"
OnItemDataBound="Repeater1_ItemDataBound">
<ItemTemplate>
<h1>Repeater 1</h1>
<asp:Repeater ID="Repeater2" runat="server" OnItemDataBound="Repeater2_ItemDataBound">
<ItemTemplate>
<h1>Repeater 2</h1>
<asp:LinkButton CommandArgument='<%#Container.ItemIndex%>' CommandName="cmdDeleteItem" ID="lnkDelete" runat="server" >Delete</asp:LinkButton>
</ItemTemplate>
</asp:Repeater>
</ItemTemplate>
</asp:Repeater>
这是背后的代码:
protected void Repeater2_ItemCommand(object source, RepeaterCommandEventArgs e)
{
switch (e.CommandName)
{
case "cmdDeleteItem":
{
var Repeater2= (Repeater)e.Item.FindControl("Repeater2");
var list = new ArrayList(Repeater2.Items);
list.Add(Repeater2.Items.Count);
Repeater2.DataSource = list;
Repeater2.DataBind();
}
break;
}
}
Repeater2_ItemCommand 事件可能找不到自己的Repeater (Repeater2)。