Datagrid Button Column with ImageButton

Discussion in 'ASP .Net' started by MattB, Apr 18, 2005.

  1. MattB

    MattB Guest

    I have a button column in a datagrid that is the delete button. Right
    now it is just a text link. When I go into the Property Builder My
    button choices are only LinkButton or PushButton. I'd like it to be an
    ImageButton so I tried converting the column to a Template Column.

    Then I edited the template to change the LinkButton to an ImageButton
    and replaced the text property with ans ImageURL property.

    The Datagrid looks how I wanted it with the graphic in place, but the
    delete command no longer seems to fire when I click on it.

    So I changed this working code:
    <asp:TemplateColumn>
    <ItemTemplate>
    <asp:LinkButton runat="server" Text="Delete" CommandName="Delete"
    CausesValidation="false"></asp:LinkButton>
    </ItemTemplate> </asp:TemplateColumn>

    To this:

    <asp:TemplateColumn>
    <ItemTemplate>
    <asp:ImageButton runat="server" ImageURL="images/test.gif"
    CommandName="Delete" CausesValidation="false"></asp:ImageButton>
    </ItemTemplate> </asp:TemplateColumn>

    And now I can see it causes a postback but the Delete Command does not
    fire. What am I missing? Thanks!

    Matt
    MattB, Apr 18, 2005
    #1
    1. Advertising

  2. Hi Matt,

    When you use Template Column + ImageButton (or other button), you should
    process data in DataGrid_ItemCommand event.

    if (e.CommandName.Equals("Delete")){
    // process
    }

    HTH

    Elton Wang




    "MattB" wrote:

    > I have a button column in a datagrid that is the delete button. Right
    > now it is just a text link. When I go into the Property Builder My
    > button choices are only LinkButton or PushButton. I'd like it to be an
    > ImageButton so I tried converting the column to a Template Column.
    >
    > Then I edited the template to change the LinkButton to an ImageButton
    > and replaced the text property with ans ImageURL property.
    >
    > The Datagrid looks how I wanted it with the graphic in place, but the
    > delete command no longer seems to fire when I click on it.
    >
    > So I changed this working code:
    > <asp:TemplateColumn>
    > <ItemTemplate>
    > <asp:LinkButton runat="server" Text="Delete" CommandName="Delete"
    > CausesValidation="false"></asp:LinkButton>
    > </ItemTemplate> </asp:TemplateColumn>
    >
    > To this:
    >
    > <asp:TemplateColumn>
    > <ItemTemplate>
    > <asp:ImageButton runat="server" ImageURL="images/test.gif"
    > CommandName="Delete" CausesValidation="false"></asp:ImageButton>
    > </ItemTemplate> </asp:TemplateColumn>
    >
    > And now I can see it causes a postback but the Delete Command does not
    > fire. What am I missing? Thanks!
    >
    > Matt
    >
    =?Utf-8?B?RWx0b24gVw==?=, Apr 18, 2005
    #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. =?Utf-8?B?V2FyYW4=?=

    HyperLink Column and Button Column in a DataGrid

    =?Utf-8?B?V2FyYW4=?=, Aug 9, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    593
    =?Utf-8?B?V2FyYW4=?=
    Aug 9, 2005
  2. J McD

    Click event on ImageButton column in a datagrid

    J McD, Feb 23, 2004, in forum: ASP .Net Building Controls
    Replies:
    0
    Views:
    124
    J McD
    Feb 23, 2004
  3. KJ
    Replies:
    2
    Views:
    175
    Stevie_mac
    Aug 16, 2003
  4. Ron

    ImageButton Column in DataGrid

    Ron, Jun 17, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    7
    Views:
    170
  5. jef
    Replies:
    2
    Views:
    237
Loading...

Share This Page