57059

how to know which image button I click in datalist

Question:

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

Answer1:

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"; }

Recommend

  • how to get the User control Value which is nested inside the datagrid to String
  • listview OnItemCommand dosen't fire up
  • dynamically create textbox [closed]
  • Connecting 2 dropDownLists with SqlDataSource FilterExpression inside ASP:Repeater
  • ItemCommand event not firing for DataList
  • Autocomplete with jQuery and asp.net repeater fills ID
  • Unique ID across multiple SQL servers
  • How to store a database intensive page into cache from a background process in rails
  • Single Web API controller per resource or less controllers with more custom actions?
  • ASP.NET MVC Routing strategy for static content for each View
  • mod-rewrite rule for sitemap.xml
  • How to solve the serve static content from a cookieless domain in prestashop 1.5?
  • JavaScript execCommand('copy') not working
  • How to set the scrollbar to move at last line in multiline textbox?
  • deploying Node.js app for production
  • Can I used mod_rewrite to change file extensions? .jpeg to .jpg for example
  • Cache is client side or server side?
  • Confused about how to update my datasources on my UITableView after app has been released
  • Serving files from BlobStore in GAE
  • Django how to modify database records by template
  • How to use compare validator to compare the data between two dropdownlists values?
  • Java ClassLoader Confusion
  • AOT and JIT with build-optimizer
  • How to change display text in item template based on eval in gridview?
  • When interface inheritance in Java is useful?
  • ASP.NET RegularExpressionValidator, validate on a non-match?
  • Mercurial: Identify file name after rename
  • File extension of zlib zipped html page?
  • Outlines on links in IE9 remains when focus is changed
  • D3 get axis values on zoom event
  • Adjust width of select element according to selected option's width
  • Custom validator control occupying space even though display set to dynamic
  • OpenGL 3.3 on Mac OSX El Capitan with LWJGL
  • Change multiple background-images with jQuery
  • Why doesn't :active or :focus work on text links in webkit? (safari & chrome)
  • Change an a tag attribute in JavaScript based on screen width
  • How to show dropdown in excel using jrxml (jasper api)?
  • NSLayoutConstraint that would pin a view to the bottom edge of a superview
  • How get height of the a view with gone visibility and height defined as wrap_content in xml?
  • python draw pie shapes with colour filled