Click here to Skip to main content
16,004,761 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

My imagebutton in placed in a datalist and my onclick event of the imagebutton is as follows.

C#
protected void MakeImg1Main(object sender, EventArgs e)
{
   //Then try like this.
   string ID = ((ImageButton)sender).ID;
   string CLientID = ((ImageButton)sender).ClientID;
}


but event is not fired .

Any help is appriciated.

Thanks in advance.
Posted

1 solution

<asp:datalist id="dataListEmp" onitemcommand="DatalistcommandEvent" repeatcolumns="1" cellspacing="10" gridlines="Both" itemstyle-width="300" itemstyle-bordercolor="Blue" borderstyle="Dotted" cellpadding="10" bordercolor="Blue" runat="server" datasourceid="sqlDataSourceEmp" xmlns:asp="#unknown">

<itemtemplate>


<%# Eval("EmpId") %>
<%# Eval("Employee Name") %>
<%# Eval("Location") %>
<asp:imagebutton runat="server" id="imgData" alternatetext="Image" commandname="Myimage">



When you click on the "Image" command event will fire and the image will be bind to image button

protected void DatalistcommandEvent(object s,DataListCommandEventArgs e)
{

if (e.CommandName == "Myimage")
{

DataListItem item = dataListEmp.Items[e.Item.ItemIndex] as DataListItem;
ImageButton imgbtn = item.FindControl("imgData") as ImageButton;
imgbtn.ImageUrl = "http://localhost:64452/FilesReadAndInsert/Images/dave.jpg";
}

}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900