Click here to Skip to main content
15,912,082 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,

I have a gridview with edit and delete buttons.

While clicking on delete button the record gets deleted immediately.What I want is on clicking delete button i should get a confirmation box.

Can any one help me on this ? If possible please provide me with a piece of code.
Posted

Use this script :

XML
<script type="text/javascript">
function ConfirmationBox(username) {

var result = confirm('Are you sure you want to delete '+username+' Details' );
if (result) {

return true;
}
else {
return false;
}
}
</script>


<asp:LinkButton ID="lnkdelete" runat="server" OnClick="lnkdelete_Click">Delete User</asp:LinkButton>


Accept as answer and vote if solve your problem.
 
Share this answer
 
Hi you could use this:

C#
DialogResult dialogResult = MessageBox.Show("Are you sure you want to delete this data?", "Deleting File", MessageBoxButtons.YesNo);
if(dialogResult == DialogResult.Yes)
{
    //Your Deleting Process
}
else if (dialogResult == DialogResult.No)
{
    //do something else
}
 
Share this answer
 
v2
C#
<asp:gridview id="GridView1" runat="server" autogeneratecolumns="False" datakeynames="id" datasourceid="SqlDataSource1" onrowdatabound="GridView1_RowDataBound">
<columns>
   <asp:commandfield showdeletebutton="True" />
   <asp:boundfield datafield="id" headertext="id" readonly="True" sortexpression="id" />
   <asp:boundfield datafield="name" headertext="name" sortexpression="name" />
</columns>
</asp:gridview>

C#
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
           Button delete =   e.Row.Cells[0].Controls[0] as Button;
           delete.Attributes.Add("onclick","return confirm('Are you sure you want to delete?');");
        }
    }

Refer this too:

GridView Delete, with Confirmation[^]

Regards :laugh:
 
Share this answer
 
v4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900