Datagrid / image button to edit

G

Guest

Is there any way to display an image button instead of the traditional
Edit/Update/Cancel push button in a datagrid (with bound data)?
 
J

Joe Fallon

Sure. Just use a Template column. This sample has 2 buttons in it - Edit and
Delete.
Note the Delete is wrappen in a Span tag which pops up a Confirm dialog
prior to posting to the server.
If the user clicks No then the dialog closes and no postback occurs. If they
click Yes then the postback occurs.


<asp:TemplateColumn HeaderText="Edit and Delete Buttons">
<ItemTemplate>
<asp:imagebutton CommandName="btnEdit" id="btnEdit" runat="server"
ImageUrl="~/img/edit.gif" ToolTip="Edit"></asp:imagebutton>
<span onclick="return confirm('Do you really want to delete this
record from the system?')">
<asp:imagebutton CommandName="btnDelete" id="btnDelete"
runat="server" ImageUrl="~/img/delete.gif"
ToolTip="Delete"></asp:imagebutton>
</span>
</ItemTemplate>
</asp:TemplateColumn>
 
J

Joe Fallon

There is no source code error.
This is a copy of code from a fully functioning datagrid.

Ensure you copy all of the code including the <asp:TemplateColumn ...> tag
and place it in your datagrid. Change the name of the image and img folder
to your versions.
 
G

Guest

I'm sorry. I did that and it works now.

However, how to make the edit button functional?
i.e. makes the grid editable, provide an update button, and update the
database?
 

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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top