This is a migrated thread and some comments may be shown as answers.

Providing confirmation box before deletion in grid view

1 Answer 64 Views
Grid
This is a migrated thread and some comments may be shown as answers.
JD
Top achievements
Rank 1
JD asked on 30 Jun 2011, 07:09 PM
Hello,

Can someone tell  me how to provide a box to provide confirmation before deletion in grid view.

I have this thing in my grid view 

   <ItemTemplate>
<asp:ImageButton ID="ImageButton1" runat="server" AlternateText="Delete Customer"
OnClientClick="javascript:if(!confirm('This action will move the selected employee to his source store . Are you sure?')){return false;}"
CausesValidation="false"

OnClick = "RadGrid1_ItemDeleted1"

CommandName="Delete"
CommandArgument='<%# Eval("EmployeeNumber") %>'
ImageUrl="~/_Layouts/delete/images.jpg" />

</ItemTemplate>
Now in the click event how to I get the row for which the delete was clicked.

Thanks

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 01 Jul 2011, 05:30 AM
Hello Siddarth,
You can try the followig approach to show the row index with the confirm window.
C#:
protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
         if (e.Item is GridDataItem)
       {
           GridDataItem item = (GridDataItem)e.Item;
           ImageButton imgBtn = (ImageButton)item.FindControl("ImageButton1");        
           int index = e.Item.ItemIndex;               
           imgBtn.Attributes.Add("onclick", "deleteConfirm('"+e.Item.ItemIndex+"');");     //attaching the client event and passing the row index 
       }
}

Javascript:
function deleteConfirm(index)
 {
   confirm("are you sure to delete " + index);      
 }

Thanks,
Shinu.
Tags
Grid
Asked by
JD
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or