试图中继Asp.net图片按钮(trying Image Button in repeater As

2019-09-29 19:06发布

我有一个Repeater.I使用的ImageButton问题试过的方法很多,并没有解决疑难问题所使用的中继项命令仍然没有working.when我点击的ImageButton没有发生。

<asp:ImageButton ID="ImageButton1" runat="server" Height="200px" Width="150px" ImageUrl='<%#"~/imageHandler.ashx?Mid=" + DataBinder.Eval(Container.DataItem, "Mid")%>' CommandName="img" CommandArgument='<%#Eval("Mid") %>' />

  protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        ModalPopupExtender mpe = (ModalPopupExtender)e.Item.FindControl("mpe");
        LinkButton Lbtn = (LinkButton)e.Item.FindControl("LinkButton1");
       switch (e.CommandName)
        {
            case "btn1":

                Session["id"] = Lbtn.CommandArgument.ToString();

                mpe.Show();

                break;
            case "img":
                Response.Write("event is fired");
                break;

            default:
                break;

Answer 1:

看看下面的代码片段。 你的LinkBut​​ton的代码似乎是正确的,但是你的加入OnItemCommand到Repeater?

<asp:Repeater ID="Repeater1" runat="server" OnItemCommand="Repeater1_ItemCommand">
    <ItemTemplate>
        <asp:ImageButton ID="ImageButton1" runat="server" CommandName="img" CommandArgument='<%#Eval("Mid") %>' />
    </ItemTemplate>
</asp:Repeater>

后面的代码

protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
{
    string commandArgument = e.CommandArgument.ToString();

    if (e.CommandName == "img")
    {
        Response.Write("event is fired: " + commandArgument);
    }
    else if (e.CommandName == "btn1")
    {
        Session["id"] = commandArgument;
    }
}


文章来源: trying Image Button in repeater Asp.net