Adding Javascript Alert for Delete button in Gridview

hi all,
to give a alert before deleting a recored form gridview u can use this code.
First u place a linkbutton in gridview colums as shown below.
COde:
AutoGenerateColumns="False" Width="100%" OnRowEditing="gvdemo_RowEditing" DataKeyNames="bigint_DemoId" OnRowDataBound="gvdemo_RowDataBound" OnRowCommand="gvdemo_RowCommand">


























Delete









COde For DElete link Button separately:


Delete




COde To Add ALert :
For this we use Grid view Row bound event
code:
protected void gvdemo_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
Button imgdelete = (Button)e.Row.FindControl("imgdelete");//Find the button
imgdelete.Attributes.Add("onclick", "javascript:return " +
"confirm('Are you sure you want to delete " +
DataBinder.Eval(e.Row.DataItem, "var_DemoDate") + " " +
DataBinder.Eval(e.Row.DataItem, "var_DemoTime") + "')");// alert adding
}
}


Happy coding...


Comments

No responses found. Be the first to comment...


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: