3

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

但是,当我按下编辑按钮并进行更改并按下更新链接时,记录不会更新并离开编辑模式......它只是停留在编辑模式,不会发生任何错误。

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

有人会认为您可以阅读文档,但我一直无法找到明确的答案。

谢谢


<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
4

2 回答 2

8

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

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

直接绑定到数据表时,您必须手动处理更新。这是因为为 CRUD 操作提供“自动”逻辑的是数据源控件,而不是 RadGrid。幸运的是,如果这是您喜欢的路径,手动处理更新并不难。查看 Telerik.com 上的一些演示以获取示例:

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

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

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

希望有帮助!-托德

于 2009-02-06T05:51:16.887 回答
2

Telerik 论坛已经回答了您的问题:

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

于 2009-02-05T15:34:10.847 回答