Server Side Deletes

3 posts, 0 answers
  1. Robert
    Robert avatar
    2 posts
    Member since:
    Jun 2018

    Posted 19 Nov 2018 Link to this post

    Is there any way to delete a record server side from a control outside of the RadGrid and have the grid update when the postback returns?

    I have a LinkButton that handles deleting a record from the datasource and then calls the RadGrid Rebind method.

    This triggers the NeedDataSource() method to fire and subsequently the RadGrid PreRender.  The problem is that when the page finishes the postback, the deleted row is still visible in the grid.  Any other interaction with the grid such as selecting a row or sorting, calls NeedDataSource again and the deleted row is gone.

    I've verified that the data that comes back to NeedDataSource right after delete does not contain the row that was deleted.  

    There is a similar "Add" functionality that works fine.  Meaning the row is added, data updated and Rebind called and grid shows the new row.  I presume this is because the add calls a RadWindow that is still within the RadPanel that contains the RadGrid whereas the Delete button is outside of the Panel.


    Here is the psuedo code of what I'm doing.

    Private Sub ibtnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ibtnDelete.Click
    End Sub
    Private Sub DeleteRecord()
    End Sub
    Protected Sub RadGrid1_NeedDataSource(ByVal source As Object, ByVal e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles RadGrid1.NeedDataSource
        RadGrid1.DataSource = FetchDataSourceHere()
    End Sub


    Here is a mockup of the aspx side.

    <asp:LinkButton ID="ibtnDelete" CssClass="icon delete" TabIndex="10" runat="server" ToolTip="Delete Current Record"
    ClientClick="return confirm('Are you sure you want to delete this record? If yes, click OK.');"></asp:LinkButton>
    <telerik:RadAjaxPanel runat="server" ID="RadAjaxPanel1" LoadingPanelID="RadAjaxLoadingPanel1" CssClass="controlsWrapper">
        <telerik:RadGrid RenderMode="Lightweight" runat="server" ID="RadGrid1" OnNeedDataSource="RadGrid1_NeedDataSource"
            AllowPaging="True" AllowSorting="true" AutoGenerateColumns="false"


    I have also tried adding ibtnDelete to the RadAjaxManager with the RadGrid, but that did not resolve anything.

  2. Robert
    Robert avatar
    2 posts
    Member since:
    Jun 2018

    Posted 20 Nov 2018 in reply to Robert Link to this post

    I'm still interested in knowing if there is a way to do this as described in the original post, but in case someone finds this and needs a work-around:

    Add these properties to the grid:

    OnDeleteCommand="RadGrid1_DeleteCommand" AllowAutomaticDeletes="true"

    Then add the method to the code behind to call your delete logic:

    Protected Sub RadGrid1_DeleteCommand(sender As Object, e As GridCommandEventArgs)
    End Sub


    Call a javascript method from your button:

    <asp:LinkButton ID="ibtnDelete" CssClass="icon delete" TabIndex="10" runat="server"
        ToolTip="Delete Current Record"
        ClientClick="return DeleteSelectedRow();"></asp:LinkButton>


    function DeleteSelectedRow() {
        if (confirm('Are you sure you want to delete this record? If yes, click OK.')) {
            var grid = $find("RadGrid1");
            var masterTableView = grid.get_masterTableView();
        return false;


    This will trigger the grid's postback to call the DeleteCommand performing the data delete.  The "return false;" will prevent the linkbutton from also posting back.  I believe masterTableView.deleteSelectedItems() actually returns false, but I didn't see documentation to confirm if that was by design or for something else.

  3. Eyup
    Eyup avatar
    4074 posts

    Posted 22 Nov 2018 Link to this post

    Hello Robert,

    Your updating logic is correct. The issue is most probably related to the button being outside of the RadAjaxPanel. If you temporarily remove AJAX, you can probably verify that the functionality works as expected:

    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Back to Top