New to Telerik UI for ASP.NET AJAX? Download free 30-day trial

Rebind Grid with EnableViewState = false

This topic discusses how to call the NeedDataSource event after command execution with viewstate disabled (EnableViewState = false)

The example provided below is for Delete command but the same stands for any other command type you invoke and handle in the ItemCommand/UpdateCommand/DeleteCommand/etc. handler of Telerik RadGrid.

Basically, you assign data source for your grid in the NeedDataSource handler. In case of disabled viewstate the events will be fired like this:

  1. LoadViewState (the grid does not restore its state from the ViewState because of the NoPersistence mode)

  2. PageLoad

  3. NeedDataSource (this is the moment when grid restores its state)

  4. ItemCommand (CommandName = "Delete")

  5. DeleteCommand

  6. NeedDataSource (refresh the data after an item was deleted)

Note that in order to make 4 to happen, the recreation of the grid in 3 should be exactly the same as when the grid is data-bound on the previous postback. To ensure that 6 will be fired, you should have set the DataSource of Telerik RadGrid to null/Nothing in 4 or 5

Moreover, if you want to rebind the grid explicitly from postback event of an external control when EnableViewState is set to False, set the DataSource property of the control to null/Nothing and invoke the Rebind() method afterwards:

protected void MyButton_Click(object sender, EventArgs e)
    //perform some actions here
    RadGrid1.DataSource = null;

    //call the Rebind() method after nullifying the data source
Protected Sub MyButton_Click(ByVal sender As Object, ByVal e As EventArgs) Handles MyButton.Click
    'perform some actions here
    RadGrid1.DataSource = Nothing
    'call the Rebind() method after nullifying the data source 
End Sub

See Also

In this article