DataList Images click

F

Fabrizio

Hi,
In my project I'm creating a dataset that will show items with pictures on a
datalist.
I use an imagebutton for each record in a datalist, and I would like to
associate the on click event with the Imagebutton for each different item.
When I try to associate a "onclick" event,simply doesn't work.
that's the code I use once the dataset is created and after the databind of
the datalist :

foreach (DataListItem item in datalist1.Items)
{
[-......]
minia01 = new ImageButton();

[...]
minia01 = (ImageButton)item.FindControl("minia01");
minia01.Click +=new ImageClickEventHandler(minia01_Click);


Any suggestion?
Thank you
Fabrizio
 
H

Hermit Dave

to get the event handling within a datalist or a datagrid you will have to
use their ItemCommand event. Implement the corresponding handler and it will
return the item on which the command was executed.. ie the say like the 5th
element.
and it has something called CommandName and CommandArguments.

so you can use those to execute whatever you wish to execute.

the way you are doing unfortunately doesnt work cause DataItem bubbles the
event the parent container.
--

Regards,

Hermit Dave
(http://hdave.blogspot.com)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,050
Latest member
AngelS122

Latest Threads

Top