I have a GridView which has a delete link to delete a record. I have created a DeleteButtonField class but I want to replace the text with an image (an icon). Is this possible? Here's my GridView:
<asp:GridView
ID="GridView1"
runat="server"
<.. removed dome properties ..>
>
<Columns>
<CustomControls:DeleteButtonField ConfirmText="Delete this record?" />
<.. other columns ..>
</Columns>
</asp:GridView>
and here's my DeleteButtonField class:
using System;
using System.Web.UI.WebControls;
namespace CustomControls
{
public class DeleteButtonField : ButtonField
{
private string _confirmText = "Delete this record?";
public string ConfirmText
{
get { return _confirmText; }
set { _confirmText = value; }
}
public DeleteButtonField()
{
this.CommandName = "Delete";
this.Text = "Delete";
this.ImageUrl = "App_GlobalResources/Del.png"; // doesn't work
}
public override void InitializeCell(DataControlFieldCell cell, DataControlCellType cellType, DataControlRowState rowState, int rowIndex)
{
base.InitializeCell(cell, cellType, rowState, rowIndex);
if (cellType == DataControlCellType.DataCell)
{
WebControl button = (WebControl)cell.Controls[0];
button.Attributes["onclick"] = String.Format("return confirm('{0}');", _confirmText);
}
}
}
}
Is this possible? As you can see I add the following code to my DeleteButtonField.cs class but it had no effect: this.ImageUrl = "App_GlobalResources/Del.png";
Thanks.