I want to change imageurl which image button I click in datalist.So I must get a diffence propertie of imagebutton in datalist.My code is below;
<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>
and my cs.codes;
protected void datalistcevaplar_ItemCommand(object source, DataListCommandEventArgs e)
{
if (e.CommandName=="tiklanan")
{
}
}
why it doesnt fire datalistcevaplar_ItemCommand event.And how do I get which imagebutton I clicked in datalist
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
If you just want a change your selected image url, first of all you must add CommandName your ImageButton element as a below.
<asp:ImageButton ID="imgbtncevaponayla" runat="server" CommandName="btnimgbtncevaponayla" ImageUrl="~/resimler/cevaponaybeyaz.jpg"/>
You find which button selected on your .aspx.cs file and you change that image url like that:
if (e.CommandName == "btnimgbtncevaponayla")
{
ImageButton btn = e.CommandSource as ImageButton;
btn.ImageUrl = "~/resimler/different.jpg";
}
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0