我想更改imageurl我在datalist中点击的图像按钮。所以我必须在datalist中获得图像按钮的差异属性。我的代码如下;
<asp:DataList ID="datalistcevaplar" runat="server"
Width="740px" OnItemCommand="datalistcevaplar_ItemCommand" >
<ItemTemplate>
<div class="divcvponay">
<asp:ImageButton ID="imgbtncevaponayla" runat="server" OnCommand="tiklanan" ImageUrl="~/resimler/cevaponaybeyaz.jpg"/>
</div>
</ItemTemplate>
</asp:DataList>
和我的cs.codes;
protected void datalistcevaplar_ItemCommand(object source, DataListCommandEventArgs e)
{
if (e.CommandName=="tiklanan")
{
}
}
为什么它不会触发datalistcevaplar_ItemCommand事件。如何获取我在datalist中单击的图像按钮
答案 0 :(得分:0)
如果您只想更改所选图像网址,首先必须将ImageButton元素的CommandName添加为如下所示。
<asp:ImageButton ID="imgbtncevaponayla" runat="server" CommandName="btnimgbtncevaponayla" ImageUrl="~/resimler/cevaponaybeyaz.jpg"/>
您可以在.aspx.cs文件中找到选择的按钮,并将该图像更改为:
if (e.CommandName == "btnimgbtncevaponayla")
{
ImageButton btn = e.CommandSource as ImageButton;
btn.ImageUrl = "~/resimler/different.jpg";
}