Display a warning message when the user clicks Delete in a ListView Control
It will be always helpful to ask user before they actually delete the row from the ListView and eventually from the database. We could display a warning message whether they really intend to delete the row. If the reply is either yes or OK, then we could carry out with the actual removal of the rows from the database.
This can be done using the following technique:
During the ItemDataBound event, we can attach a client side event for each Delete Link in the ListView control.
Code:
protected void DataBoundList(Object sender, ListViewItemEventArgs e)
{
if (e.Item.ItemType == ListViewItemType.DataItem)
{
LinkButton lnkDelete = (LinkButton)e.Item.FindControl("lnkDelete");
if (lnkDelete != null)
{
lnkDelete.Attributes.Add("onclick",
"return confirm('Are you sure you want to delete this author?');");
}
}
} Clicking on the delete link will result in the following alert box. If the user clicks cancel, then the delete operation will not be carried out.
__________________
S.VinothkumaR
Behind me is infinite power,
Before me is Endless Possibility,
Around me is Boundless Opportunity,
Why should I fear!