Click here to Skip to main content
15,867,488 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
hello friends

when we click delete button in default gridview first it asks confirmation after that it ll delete.

if we are having delete button in footer means by onclient click command we can use alert before delteting..

tel me how to do?
Posted

For adding a delete prompt, you would need to bind the JavaScript to prompt for this alert during the ItemDataBound event of the datagrid (or RowDatabound of Gridview).

In this event, while the data is binded row by row - add something like:
C#
LinkButton l = (LinkButton)e.Row.FindControl("LinkButton1"); 
l.Attributes.Add("onclick", "javascript:return " +
    "confirm('Are you sure you want to delete this record')"); 
Alternatively,
if the link button in ItemTemplate of datagrid has OnclientClick event exposed (which is present in ASP.NET2.0 onwards), you can add something like:
C#
OnClientClick = 'return confirm("Are you sure you want to delete this entry?");' 


Try!
 
Share this answer
 
try this:

VB
<asp:Button ID="DeleteButton" runat="server" OnClientClick="return confirm('Are you sure you want to delete this ?');" Font-Bold="True" Font-Size="Large" ForeColor="Blue"
        OnClick="DeleteButton_Click" Text="Delete" ToolTip="Click here to Delete this....."
        ValidationGroup="MyPersonal" Width="98px" />



and in DeleteButton_Click event write your deleting code in C#..
 
Share this answer
 
v3
Hi beginner in C#.net,

DialogResult result = MessageBox.Show("Are you sure you want to delete ?", "Message", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (result == DialogResult.Yes)
{
    // write the code to delete here
}


I hope this help,
:)
 
Share this answer
 
Comments
Groulien 31-May-11 9:43am    
The code is correct, but he's asking it for ASP.NET and not for Windows Forms (I also posted a 'forms' solution and deleted it).
feifeizhou32 31-May-11 10:32am    
hook
MuhammadSuleman761 16-Apr-12 8:58am    
Marvelous...it was exactly what I was searching for...THnx Micheal

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