auto-generate delete warning

3 posts, 1 answers
  1. Allan
    Allan avatar
    121 posts
    Member since:
    Jun 2008

    Posted 06 Sep 2010 Link to this post

    Is there a simple way to add an delete warning to the auto-generate delete in RadGrid?
  2. Answer
    Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 07 Sep 2010 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Allan
    Allan avatar
    121 posts
    Member since:
    Jun 2008

    Posted 07 Sep 2010 Link to this post

    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
Back to Top