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

auto-generate delete warning

2 Answers 108 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Allan
Top achievements
Rank 2
Allan asked on 07 Sep 2010, 03:43 AM
Is there a simple way to add an delete warning to the auto-generate delete in RadGrid?

2 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 07 Sep 2010, 06:55 AM
Hello Allan,

 You can access the AutoGeneretedDeleteColumn from code behind and can attach a confirmation dialog to its onclick attribute to display notification for the user when he clicks that button.

C#:
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
{
  if(e.Item is GridDataItem)
    {
        GridDataItem item=(GridDataItem)e.Item;
        LinkButton lnkBtnDelete = (LinkButton)item["AutoGeneratedDeleteColumn"].Controls[0];
        lnkBtnDelete.Attributes["onclick"] = "javascript:return confirm(\'Do you want to delete this item?\')";
     }
}

Regards,
Shinu.
0
Allan
Top achievements
Rank 2
answered on 08 Sep 2010, 12:03 AM
Thanks Shinu,

Here is how I did this in VB for those who may need this assistance.

Protected Sub rg_DECsFiles_ItemCreated(ByVal sender As Object, ByVal e As GridItemEventArgs) Handles rg_DECsFiles.ItemCreated
    If TypeOf e.Item Is GridDataItem Then
        Dim item As GridDataItem = DirectCast(e.Item, GridDataItem)
        Dim deleteBtn As LinkButton = DirectCast(item.FindControl("AutoGeneratedDeleteButton"), LinkButton)
        deleteBtn.Attributes.Add("onclick", "return confirm('Are you sure you want to delete this row or record?')")
    End If
End Sub
Tags
Grid
Asked by
Allan
Top achievements
Rank 2
Answers by
Shinu
Top achievements
Rank 2
Allan
Top achievements
Rank 2
Share this question
or