none
Web开发中Repeater控件镶嵌问题 RRS feed

  • 问题

  • Repeater2是镶嵌在Repeater1中的,代码如下

           protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
            {
                if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
                {
                    HiddenField hf = (HiddenField)e.Item.FindControl("HiddenField1");
                    Repeater rt = (Repeater)e.Item.FindControl("Repeater2");
               
                    rt.ItemDataBound += new RepeaterItemEventHandler(rt_ItemDataBound);
                    rt.ItemCommand += new RepeaterCommandEventHandler(rt_ItemCommand);
                    rt.DataSource = MessageManage.ShowRefByMID(int.Parse(hf.Value));
                    rt.DataBind();
                }
            }

     void rt_ItemCommand(object source, RepeaterCommandEventArgs e)
            {
                //throw new NotImplementedException();
                Response.Write("aaa");
            }

    void rt_ItemDataBound(object sender, RepeaterItemEventArgs e)
            {
                if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
                {
                    Button bt6 = (Button)e.Item.FindControl("Button6");
                 
                    bt6.OnClientClick = "return confirm('删除该回复之后将不可恢复,确定要删除?')";

                 }

    为什么ItemDataBound事件中的代码可以执行,而ItemCommand事件却不能执行,求解释…

    2011年11月2日 14:36

答案

  • 你好,

    你需要贴出页面中的代码,方便大家更好的了解你的问题。这里有可能是页面代码中对后台的事件委托没有指定正解,页面的标签例子:

    <asp:Repeater id="Repeater1" OnItemCommand="rt_ItemCommand" runat="server">

    谢谢。


    Leo Tang [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    2011年11月7日 1:06
    版主