Telerik radGrid - possible to do use AllowAutomaticUpdates when Datasource = a dataset?

13,046

Solution 1

In short, there is one key issue at play here:

The "automatic" operations are only supported when you're using a Data Source control to bind the grid. That includes the ObjectDataSource, so you can use your DAL with the ODS and then support auto upserts/updates/deletes.

When binding directly to a data table, you must handle the updates manually. That's because it is the data source controls- not the RadGrid- that are providing the "auto" logic for CRUD operations. Fortunately, it's not hard to handle update manually if that's the path you prefer. Check out some of the demos on Telerik.com for examples:

http://demos.telerik.com/aspnet-ajax/grid/examples/dataediting/editmodes/defaultcs.aspx

You can also use the RadGrid with ViewState disabled if you want to. The best way to do that is to use the Grid's support for client-side databinding (though that does require that you expose your DAL via a Service Layer). Check out the demos for that approach here:

http://demos.telerik.com/aspnet-ajax/grid/examples/client/insertupdatedelete/defaultcs.aspx

Hope that helps! -Todd

Solution 2

Your question has already been answered in the Telerik forums:

http://www.telerik.com/community/forums/aspnet/grid/is-it-possible-to-do-automaticupdates-to-a-dataset.aspx

Share:
13,046
tbone
Author by

tbone

Updated on June 04, 2022

Comments

  • tbone
    tbone about 2 years

    I am setting the datasource of my radGrid to a dataset (that I have stored in session). I have enabled AllowAutomaticUpdates and EnableViewState, implemented NeedDataSource, set DatakeyNames, etc. (see code below)

    However, when I press the Edit button and make a change and press the Update link, the record does not update and leave Edit Mode.....it just stays in edit mode, and no error of any kind occurs.

    So, the question is....does anyone know if radGrid with EnableViewstate even supports AutomaticUpdates, so the changes in the grid will be automatically pushed into the dataset to which it is bound?

    One would think you could read the documentation, but I have been unable to find a definitive answer.

    Thanks


    <telerik:Radgrid id="grid" runat="server" AllowPaging="True" AllowSorting="True" AllowAutomaticUpdates="true" 
                AutoGenerateEditColumn="True" GridLines="None" >
    
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            If Not IsPostBack Then
                Dim data As New DataGateway
                Dim ds As DataSet = data.GetEmployeesByProgram(Year:=2009, ProgramName:="Long Term Incentive Stock Program")
                Dim dt As DataTable = ds.Tables(0)
                ds.Tables(0).PrimaryKey = New DataColumn() {dt.Columns("EmployeeNum"), dt.Columns("ProgramName"), dt.Columns("Year")}
                Session("datasource") = ds
                With Me.grid
                    .AllowAutomaticUpdates = True
                    .AutoGenerateColumns = True
                    .AllowSorting = True
                    .AutoGenerateEditColumn = True
                    .EnableViewState = True     'IS REQUIRED!!!
                    Me.grid.MasterTableView.AllowAutomaticUpdates = True
                    Me.grid.MasterTableView.EditMode = GridEditMode.InPlace
                End With
            End If
        End Sub
    
    
    
    
    Private Sub grid_NeedDataSource(ByVal source As Object, ByVal e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles grid.NeedDataSource
            Debug.WriteLine("NeedDataSource: " & e.RebindReason.ToString)
            Dim ds As DataSet = CType(Session("datasource"), DataSet)
            Me.grid.MasterTableView.DataKeyNames = New String() {"EmployeeNum", "ProgramName", "Year"}
            Me.grid.DataSource = ds
    
        End Sub
    
  • Nol
    Nol over 7 years
    This is way old at this point in time, but it's worth noting that link is dead now.