Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
Appreciate if u let me know :
 
how to display confirm dialog box before deleting a row in gridview by java script/vb script.
I search many article, but that all was making a dialog box control, which I don't like.
 
Simply , I want to display a confirm box before deleting a row from girdview(I am using Command button [Select,Delete,Edit,Update,cancel])
by the way of either JavaScript or VBScript.
 

Can anybody answer, Hoping for ur best reply
 

Thanx
Posted 13-Jun-10 21:25pm
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

Adding confirm dialog box in Command buttons Check this link.
 
GridView Delete Confirmation Using asp:CommandField[^]
  Permalink  
Comments
koool.kabeer at 31-Jul-10 4:43am
   
hey thats what he wanted.......
in the RowDataBound Event Handler of GridView just get the reference of each ImageButton Control and either add a JavaScript function as Attributes... or just add OnClientClick property value as
"if(!confirm("Are You Sure to Delete?"))
return;"
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 6

<asp:ImageButton ID="btnDelete" runat="server" CausesValidation="False" CommandName="Delete" ImageUrl="~/Image/delete.png" OnClick="btnDelete_Click" Text="Delete"
OnClientClick="return confirm('Are you sure you want to Delete this record ?')" />
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

hi friend,
see i have solution for u.
just try this.
 
Design your grid mentioned as below
<asp:templatefield showheader="False" xmlns:asp="#unknown">
     <itemtemplate>
          <asp:linkbutton id="lnkBtn" commandname="Delete" text="Delete" onclientclick="return ConfirmDelete();">
runat="server">
 
Add this java script into your aspx form
function ConfirmDelete()
{
    var Delet_Confirm= confirm("Do you really want to delete this record ?");
 if (Delet_Confirm== true)
 {
   return true;
 }
 else
 {
  return false;
  }
}
 

if you are not using template field, you can write same java script into
row command event of grid into .cs file by define tag.
 

Thanks,
Mahesh Patel
  Permalink  
v3
Comments
shanawazway at 14-Jun-10 3:14am
   
Hi Dear,
As I mentioned in my question,I am not using template field, but it is command field of gridview(Select,Delete,Edit);
How can I call JavaScript function with Gridview Command default field like "Delete".
 
Again help me out
 
Thanx
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 5

in the RowDataBound Event Handler.....
  protected void GridView_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        // loop all data rows
        foreach (DataControlFieldCell cell in e.Row.Cells)
        {
           // check all cells in one row
           foreach (Control control in cell.Controls)
           {
                // Must use LinkButton here instead of ImageButton
                // if you are having Links (not images) as the command button.
                ImageButton button = control as ImageButton;
                if (button != null && button.CommandName == "Delete")
                    // Add delete confirmation
                    button.OnClientClick = "if (!confirm('Are you sure " + 
                           "you want to delete this record?')) return;";
            }
        }
    }
}
 

 
 
Here you dont need to loop the each Cell and each Control in each Cell..
just use proper indexing... like
 
ImageButton = (ImageButton)e.Row.Cell[<<yourDeleteColumnIndex>>].Controls[<<getImageButtonControlIndex>>];
  Permalink  
Comments
makhaai at 31-Jul-10 7:46am
   
Reason for my vote of 1
I give this solution already.
koool.kabeer at 31-Jul-10 14:03pm
   
sorry friend but i didn't give the link it was just a simple thing which could be seen at the bottom of my answer... which was not in that article
koool.kabeer at 31-Jul-10 14:04pm
   
no need to use for loops i means.... by the sorry for what ever i done...
take care
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

use
response.redirect("confirm('Do you really want to delete this record')")
  Permalink  
Comments
Sandeep Mewara at 30-Jul-10 16:25pm
   
Reason for my vote of 1
Why would someone do Response.Redirect when deleting?
koool.kabeer at 31-Jul-10 4:45am
   
yeah dear....
can you explain why to use Response.Redirect here....
may be i can get something from it...
thanx in advance

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



Advertise | Privacy | Mobile
Web02 | 2.8.1411022.1 | Last Updated 25 Aug 2010
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100