Click here to Skip to main content
15,895,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hallo,

I have a grid view of a database table including edit- and delete- buttons. If the user clicks the delete button of a row, I want to ask him/her, "Are you sure?" in a messagebox with two buttons (yes/no).

How can I do that?
Posted

XML
<ItemTemplate>
<asp:LinkButton  ID="btn_Cancel"  runat="server" Text="Cancel" CommandName="cancel" OnClientClick="return confirm('Are you sure want to delete this record?')"   />
 </ItemTemplate>
 
Share this answer
 
See the Discussion
Confirm box in ASP.Net
 
Share this answer
 
it may helps you.

XML
<asp:Button   runat="server" ID="lnkDelete" CausesValidation="False" Text="Delete"
                    OnClientClick="chkDelete();"  CommandName="Delete" ></asp:Button>



then insert a HiddenField control

<asp:hiddenfield id="hdelete" runat="server" value="0" xmlns:asp="#unknown" />


write this script
XML
<script type="text/javascript">
 function chkDelete()
        {
        if(confirm("Do u want Delete?"))
        {
        document.getElementById("ctl00_ContentPlaceHolder1_GridView2_ctl02_hdelete").value="1";
        }
        else
        {
        document.getElementById("ctl00_ContentPlaceHolder1_GridView2_ctl02_hdelete").value="0";
        }
        }
</script>





then in row_deleteing event,
C#
int str = Convert.ToInt32(((HiddenField)GridView2.Rows[0].FindControl("hdelete")).Value);
       if (str == 0)
       {
           e.Cancel = true;
       }
       else
       {
           e.Cancel = false;
           // write code for delete


       }




Regards,
Palraj
 
Share this answer
 
 
Share this answer
 
Try This...

<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandName="Delete"
Text="Delete"></asp:LinkButton><cc1:ConfirmButtonExtender ID="LinkButton1_ConfirmButtonExtender"
runat="server" ConfirmText="Are you sure you want to delete?" Enabled="True"
TargetControlID="LinkButton1">
</cc1:ConfirmButtonExtender>
</ItemTemplate>
 
Share this answer
 
try this one..im not sure


Dim Answer As Integer
Answer = MessageBox.Show("Are you sure you want to delete", "", MessageBoxButtons.YesNo)

If DialogResult = Windows.Forms.DialogResult.Yes Then
\\put your delete command here
End If
 
Share this answer
 

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