Telerik radGrid-当数据源=数据集时可以使用AllowAutomaticUpdates吗? [英] Telerik radGrid - possible to do use AllowAutomaticUpdates when Datasource = a dataset?

查看:128
本文介绍了Telerik radGrid-当数据源=数据集时可以使用AllowAutomaticUpdates吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将radGrid的数据源设置为数据集(已存储在会话中). 我已启用AllowAutomaticUpdates和EnableViewState,已实现NeedDataSource,设置了DatakeyNames等(请参见下面的代码)

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.

所以,问题是....有人知道带有EnableViewstate的radGrid是否甚至支持AutomaticUpdates,因此网格中的更改将自动推入绑定到的数据集中吗?

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.

谢谢

<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

推荐答案

简而言之,这里存在一个关键问题:

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

仅当您使用数据源控件绑定网格时,才支持自动"操作.该包括 ObjectDataSource,因此您可以将DAL与ODS一起使用,然后支持自动upserts/updates/deletes.

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.

直接绑定到数据表时,必须手动处理更新.这是因为为CRUD操作提供自动"逻辑的是数据源控件(而不是RadGrid).幸运的是,如果您愿意这样做,手动处理更新并不难.请查看Telerik.com上的一些演示示例:

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

如果需要,您还可以在禁用ViewState的情况下使用RadGrid.最好的方法是使用Grid对客户端数据绑定的支持(尽管这确实要求您通过服务层公开DAL).在此处查看有关该方法的演示:

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

希望有帮助! -托德

这篇关于Telerik radGrid-当数据源=数据集时可以使用AllowAutomaticUpdates吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆