DataList Images click

Discussion in 'ASP .Net Web Controls' started by Fabrizio, Sep 18, 2004.

  1. Fabrizio

    Fabrizio Guest

    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
     
    Fabrizio, Sep 18, 2004
    #1
    1. Advertising

  2. Fabrizio

    Hermit Dave Guest

    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)
    "Fabrizio" <> wrote in message
    news:...
    > 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
     
    Hermit Dave, Sep 18, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Gönen EREN

    Datalist in Datalist How?

    Gönen EREN, Aug 22, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    414
    Gönen EREN
    Aug 22, 2003
  2. acko bogicevic

    DataList in DataList

    acko bogicevic, Nov 10, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    5,521
    acko bogicevic
    Nov 11, 2003
  3. Steve Lloyd
    Replies:
    1
    Views:
    707
    Rick Spiewak
    May 26, 2004
  4. Nevyn Twyll
    Replies:
    8
    Views:
    1,889
  5. Luis Esteban Valencia Muñoz
    Replies:
    0
    Views:
    780
    Luis Esteban Valencia Muñoz
    Jun 3, 2005
Loading...

Share This Page