在转发器Asp.net中尝试图像按钮 [英] trying Image Button in repeater Asp.net
问题描述
我在Repeater中使用imageButton时遇到问题.我尝试了很多方法,但没有解决问题.我使用repeater item命令仍然无法正常工作.当我单击imageButton时,什么也没有发生.
I have a problem using imageButton in a Repeater.I tried alot of method and didnt fix the problem.I used the repeater item command still not working.when i click on the imageButton nothing happen.
< 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;
推荐答案
看看下面的代码段.您的LinkButton代码似乎正确,但是您是否将 OnItemCommand
添加到了Repeater中?
Take a look at the snippet below. Your LinkButton code seems to be correct, but did you add the OnItemCommand
to the 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;
}
}
这篇关于在转发器Asp.net中尝试图像按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!