In this article I will explain how to
delete records in gridview with confirmation message box in ASP.NET.
In my previous article I
explained how to insert, update, Delete in gridview and Upload Images in gridview and Upload files & Download in gridview and highlight gridview rows.
User clicks on Delete link button in GridView at
that time I need to show confirmation message box and if user clicks on ok
button in confirmation message box I want to delete record from database and
rebind the gridview otherwise no action should perform on particular record.
Below is the Sample Code:
protected void gvFileDetails_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
LinkButton
btnDelete = (LinkButton)e.Row.FindControl("lnkDelete");
if (btnDelete != null)
{
btnDelete.Attributes.Add("onclick", "javascript:return
" +
"confirm('Are you sure you want to delete this
record?')");
}
}
}