Click here to Skip to main content
14,664,084 members
Rate this:
Please Sign up or sign in to 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

Rate this:
Please Sign up or sign in to vote.

Solution 2

try this:

<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#..
   
v3
Rate this:
Please Sign up or sign in to vote.

Solution 4

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:
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:
OnClientClick = 'return confirm("Are you sure you want to delete this entry?");' 


Try!
   
Rate this:
Please Sign up or sign in to vote.

Solution 1

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,
:)
   
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, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100