Datagrid Button Column with ImageButton

M

MattB

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
 
G

Guest

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
(e-mail address removed)
 

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,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top