2009-01-28 25 views
2

我正在將我的radGrid的數據源設置爲一個數據集(我存儲在會話中)。 我已啓用AllowAutomaticUpdates和EnableViewState,實現了NeedDataSource,設置DatakeyNames等(請參閱下面的代碼)Telerik radGrid - Datasource =數據集時可以使用AllowAutomaticUpdates嗎?

但是,當我按下Edit按鈕並進行更改並按Update鏈接時,記錄不會更新並離開編輯模式.....它只是停留在編輯模式,並沒有任何錯誤發生。

所以,問題是......有誰知道如果radGrid與EnableViewstate甚至支持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 

回答

6

總之,是在這裏打一個關鍵問題:

只有使用a時才支持「自動」操作數據源控件綁定網格。 包含 ObjectDataSource,因此您可以將DAL與ODS一起使用,然後支持自動插入/更新/刪除。

當直接綁定到數據表時,您必須手動處理更新。這是因爲它是數據源控件(而不是RadGrid)爲CRUD操作提供了「自動」邏輯。幸運的是,如果這是您喜歡的路徑,手動處理更新並不困難。檢查出一些對Telerik.com演示爲例子:

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

您還可以,如果你想使用的radgrid控件禁用ViewState中。最好的方法是使用Grid支持客戶端數據綁定(儘管這需要您通過服務層公開您的DAL)。退房的演示,這種方法在這裏:

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

希望幫助! -Todd