How to react to an ImageButon in a DataList ?

Discussion in 'ASP .Net Web Controls' started by Gilles Lambert, May 19, 2005.

  1. Hi,

    I'm used to LinkButtons with CommandName property (Update, Delete, etc.)
    in a DataList to get the correspondind events, but it does'nt work with
    an ImageButton. The PostBack seems to appen, but the event handler is
    not called. So i'm sure it's possible to use other kind of butons than
    LinkButon, typically an ImageButton, but i don't understand why it
    does'nt works ?

    Thanks and best regards
    GL



    *** Sent via Developersdex http://www.developersdex.com ***
     
    Gilles Lambert, May 19, 2005
    #1
    1. Advertising

  2. Gilles Lambert

    EJD Guest

    Hi -
    I believe that in order to capture control events when they are
    templated items you have to create the event handler for the
    "ItemCommand" for the DataList. After creating the event handler in
    the code behind, I edited the page in HTML and added the following
    CommandName and CommandArgument for the image button. I bound the
    orderId from the Northwind database orders table so that when the
    button is clicked the command argument is actually the orderId.

    <asp:datalist id=DataList1 style="Z-INDEX: 101; LEFT: 112px; POSITION:
    absolute; TOP: 40px" runat="server" DataMember="Orders"
    DataKeyField="OrderID" DataSource="<%# dataSet11 %>">
    <ItemTemplate>
    <asp:ImageButton id="ImageButton1" runat="server" ImageUrl="..."
    CommandName="transfer" CommandArgument='<%# DataBinder.Eval(Container,
    "DataItem.orderid") %>'></asp:ImageButton>
    </ItemTemplate>
    </asp:datalist>

    In the code behind I handled the click like this:
    private void DataList1_ItemCommand(object source,
    System.Web.UI.WebControls.DataListCommandEventArgs e)
    {
    // sling takes the orderId, and it can be used for
    whatever...
    string sling = e.CommandArgument.ToString();
    Server.Transfer("aPage.aspx");
    }

    The same applies to DataGrids as well...and perhaps some other controls
    as well...

    HTH, and good luck!
    EJD
     
    EJD, May 20, 2005
    #2
    1. Advertising

  3. Gilles Lambert

    EJD Guest

    Oh, and another thing. I've noticed that from time to time after
    modifying a DataGrid or DataList that sometimes that events that you
    had created for the control using the designer or whatever just seem to
    stop working. As in the code is still there in the code behind, but
    the event handler has lost its link to the control. I don't know if
    that applies here...

    EJD
     
    EJD, May 20, 2005
    #3
  4. Everthing is OK with a LinkButton, but nothing to do with an
    ImageButton. So, i've found a solution with an simple image inside à
    LinkButton and it works !

    <asp:LinkButton id="Linkbutton2" runat="server" Width="50px"
    CommandName="Delete">
    <IMG alt="" src="images/btn_delete.gif" border="0"></asp:LinkButton>

    Thanks ;-)
    Gilles


    *** Sent via Developersdex http://www.developersdex.com ***
     
    Gilles Lambert, May 20, 2005
    #4
    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. =?Utf-8?B?SmltIEhlYXZleQ==?=

    Buttons Do Not React

    =?Utf-8?B?SmltIEhlYXZleQ==?=, Jul 5, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    491
    Natty Gur
    Jul 6, 2004
  2. Nevyn Twyll
    Replies:
    8
    Views:
    1,882
  3. Rob Meade

    ImageButon: PostBackURL

    Rob Meade, Dec 4, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    1,539
    Teemu Keiski
    Dec 4, 2005
  4. diegomrosa
    Replies:
    1
    Views:
    401
    Robert Iver
    Jun 9, 2006
  5. Barry
    Replies:
    5
    Views:
    874
    Barry
    Jan 26, 2007
Loading...

Share This Page