Javascript code to Delete item confirmation
<script type="text/javascript" language="javascript">
function ConfirmOnDelete(item) {
if (confirm("Are you sure to delete: " + item + "?") == true)
return true;
else
return false;
}
</script>
This is the Backend code to Delete from the list
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
DataTable dt = (DataTable) ViewState["dtDatas"];
dt.Rows[e.RowIndex].Delete();
dt.AcceptChanges();
ViewState["dtDatas"] = dt;
GridView1.DataSource = dt;
GridView1.DataBind();
lblMsg.Text = "Row deleted";
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowState != DataControlRowState.Edit)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
string pid = e.Row.Cells[0].Text;
LinkButton lb = (LinkButton)e.Row.Cells[6].Controls[0];
if (lb != null)
{
lb.Attributes.Add("onclick", "return ConfirmOnDelete('" + pid + "');");
}
}
}
}
