首页 新闻 会员 周边 捐助

Repeater嵌套 内部Repeater的ItemCommand事件如何注册?

0
悬赏园豆:50 [已解决问题] 解决于 2015-06-18 18:10
<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>");
   }
}

内部删除事件始终无法激发,页面源代码也没有添加注册事件!

求解!

黑白*郎君的主页 黑白*郎君 | 初学一级 | 园豆:121
提问于:2013-01-04 15:43
< >
分享
最佳答案
0
<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>");
   }
}
收获园豆:20
psforever | 菜鸟二级 |园豆:461 | 2013-01-06 01:10
其他回答(3)
0

你注册的名字不对呀

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>");
   }
}

收获园豆:10
Rich.T | 园豆:3440 (老鸟四级) | 2013-01-04 16:09

不好意思 写错了 名称改好依旧不行!多些提醒

支持(0) 反对(0) 黑白*郎君 | 园豆:121 (初学一级) | 2013-01-05 09:15
0


<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>
收获园豆:10
Tom.汤 | 园豆:3060 (老鸟四级) | 2013-01-05 13:00
0
Repeater 嵌套另一个Repeater 控件,方法注册到里面Repeater控件中就行了。外面的控件找不到里面控件LinkButtion的CommandName
 
收获园豆:10
卒子 | 园豆:588 (小虾三级) | 2013-01-05 15:17
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册