<asp:Repeater ID="rptparent" runat="server" OnItemCreated="rptparent_ItemCreated"> <ItemTemplate> <asp:Repeater ID="rptsub" runat="server"> <ItemTemplate> <asp:LinkButton ID="lbDel" CommandName="delete" runat="server" OnClientClick="javascript:return confirm( '确定要删除吗? ');">删除</asp:LinkButton> </ItemTemplate> </asp:Repeater> </ItemTemplate> </asp:Repeater>
rptparent的item创建时手动注册了内部rptsub的ItemCommand事件
void rptparent_ItemCreated(object sender, RepeaterItemEventArgs e) { if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { Repeater rptare = e.Item.FindControl("rptsub") as Repeater; rptare.ItemCommand += new RepeaterCommandEventHandler(rptare_ItemCommand); } } void rptare_ItemCommand(object sender, RepeaterItemEventArgs e) {
if (e.CommandName.ToLower() == "delete")
{
Response.Write("<script>alert('内部删除事件!')</script>");
}
}
内部删除事件始终无法激发,页面源代码也没有添加注册事件!
求解!
<asp:Repeater ID="rptparent" runat="server" OnItemDataBound="rptparent_ItemDataBound"> <ItemTemplate> <asp:Repeater ID="rptsub" runat="server"> <ItemTemplate> <asp:LinkButton ID="lbDel" CommandName="delete" runat="server" OnClientClick="javascript:return confirm( '确定要删除吗? ');">删除</asp:LinkButton> </ItemTemplate> </asp:Repeater> </ItemTemplate> </asp:Repeater>
void rptparent_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
Repeater rptare = e.Item.FindControl("rptsub") as Repeater;
rptare.ItemCommand += new RepeaterCommandEventHandler(rptare_ItemCommand);
}
}
void rptare_ItemCommand(object sender, RepeaterItemEventArgs e)
{
if (e.CommandName.ToLower() == "delete")
{
Response.Write("<script>alert('内部删除事件!')</script>");
}
}
你注册的名字不对呀
void rptparent_ItemCreated(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
Repeater rptare = e.Item.FindControl("rptsub") as Repeater;
rptare.ItemCommand += new RepeaterCommandEventHandler(rptare_ItemCommand);
}
}
void rptare_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.CommandName.ToLower() == "delete")
{
Response.Write("<script>alert('内部删除事件!')</script>");
}
}
不好意思 写错了 名称改好依旧不行!多些提醒
<asp:Repeater ID="rptparent" runat="server">
<ItemTemplate>
<asp:Repeater ID="rptsub" runat="server" OnItemCommand="rptare_ItemCommand" > <ItemTemplate> <asp:LinkButton ID="lbDel" CommandName="delete" runat="server" OnClientClick="javascript:return confirm( '确定要删除吗? ');">删除</asp:LinkButton> </ItemTemplate> </asp:Repeater>
</ItemTemplate> </asp:Repeater>
Repeater 嵌套另一个Repeater 控件,方法注册到里面Repeater控件中就行了。外面的控件找不到里面控件LinkButtion的CommandName