Sunday, November 29, 2009

Confirmation before deleting a row with the gridview control













protected void GVEditCenter_RowDataBound(object sender, GridViewRowEventArgs e)
{

AddConfirmDelete((GridView)sender, e);
}


public static void AddConfirmDelete(GridView gv, GridViewRowEventArgs e)
{
if (e।Row।RowType == DataControlRowType।DataRow)
{
foreach (DataControlField dcf in gv।Columns)
{
if (dcf।ToString() == "CommandField")
{
if (((CommandField)dcf)।ShowDeleteButton == true)
{
e।Row।Cells[gv।Columns।IndexOf(dcf)]।Attributes
।Add("onclick", "return confirm(\"Are you sure?\")");
}
}
}
}
}

No comments:

Post a Comment