Add the follow to web.config
<pages>
<controls>
<!--custom defined tag prefix for extending delete function of gridview to have confirming function -->
<add tagPrefix="custom" namespace="CustomControl"/>
</controls>
</pages>


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI.WebControls;
namespace CustomControl
{
public class DeleteButtonField:ButtonField
{
private String ConfirmMsg = "If you want to delete?";
public DeleteButtonField()
{
this.CommandName = "Delete";
this.Text = "Delete";
}
public override void InitializeCell(DataControlFieldCell cell, DataControlCellType cellType, DataControlRowState rowState, int rowIndex)
{
base.InitializeCell(cell, cellType, rowState, rowIndex);
if (cellType == DataControlCellType.DataCell)
{
WebControl wc = cell.Controls[0] as WebControl;
wc.Attributes["onclick"] = String.Format("return confirm('{0}');", ConfirmMsg);
}
}
}
}
and use it like


<asp:GridView ID="GridView1" runat="server">
<Columns>
<custom:DeleteButtonField></custom:DeleteButtonField>
</Columns>
</asp:GridView>