Radgrid Edit Form Update through TableAdapter

2 posts, 1 answers
  1. Chris
    Chris avatar
    5 posts
    Member since:
    May 2014

    Posted 08 May 2015 Link to this post

    I am having an issue with following the demo located at (http://demos.telerik.com/aspnet-ajax/grid/examples/data-editing/edit-form-types/defaultcs.aspx)

    I have been able to get the radgrid to fill with my datasource, see the edit column and popsup the edit form as I have formated it. But when I make the "Edit" and choose the "Update" nothing happens. The values seem to be getting saved, but there not going to the database. The AcceptChanges() command is where I believe it is not saving to the database.  

    Below is my code behind. Any help would be appreciated. Thank you in advance.


    Partial Class Member

    Public Function GetDataTable(ByVal query As String) As DataTable 

            Dim ConnString As String = ConfigurationManager.ConnectionStrings("DatabaseName").ConnectionString

            Dim conn As SqlConnection = New SqlConnection(ConnString)

            Dim adapter As SqlDataAdapter = New SqlDataAdapter

            adapter.SelectCommand = New SqlCommand(query, conn)

            Dim table1 As New DataTable






            End Try

            Return table1

        End Function 

        Public ReadOnly Property Members() As DataTable


                Dim obj As Object = Me.Session("Members")

                If (Not obj Is Nothing) Then

                    Return CType(obj, DataTable)

                End If

        Dim dtblMember As New Main.tblMemberDataTable       

    dtblMember = memberAdapter.GetAllMemberInfo()

                Me.Session("Members") = dtblMember

                Return dtblMember 

            End Get

        End Property

        Protected Sub rgMember_NeedDataSource(ByVal source As Object, ByVal e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles rgMember.NeedDataSource 

            Me.rgMember.DataSource = Me.Members

            Me.Members.PrimaryKey = New DataColumn() {Me.Members.Columns("MemberID")}

     End Sub

         Protected Sub rgMember_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles rgMember.PreRender

            If Not IsPostBack And Me.rgMember.MasterTableView.Items.Count > 1 Then

                'This sets the specified item to default to edit mode on load when set to True.

                Me.rgMember.MasterTableView.Items(1).Edit = False           


            End If

        End Sub

        Protected Sub rgMember_UpdateCommand(ByVal source As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles rgMember.UpdateCommand

            Dim editedItem As GridEditableItem = CType(e.Item, GridEditableItem)

            Dim MyUserControl As UserControl = CType(e.Item.FindControl(GridEditFormItem.EditFormUserControlID), UserControl)

    'Locate the changed row in the DataSource
            Dim changedRows As DataRow() = Me.Members.Select("MemberID = " & editedItem.OwnerTableView.DataKeyValues(editedItem.ItemIndex)("MemberID"))

            If (Not changedRows.Length = 1) Then

                e.Canceled = True


            End If 

            'Update new values

            Dim newValues As Hashtable = New Hashtable 

            newValues("Designation") = CType(MyUserControl.FindControl("txtDesignation"), TextBox).Text

            newValues("AppointedDate") = CType(MyUserControl.FindControl("rdpAppointedDate"), RadDatePicker).SelectedDate.ToString()

            newValues("EffectiveDate") = CType(MyUserControl.FindControl("rdpEffectiveDate"), RadDatePicker).SelectedDate.ToString()

            newValues("TermExpireDate") = CType(MyUserControl.FindControl("rdpTermExpireDate"), RadDatePicker).SelectedDate.ToString()

            newValues("ChairID") = CType(MyUserControl.FindControl("ddlChair"), RadDropDownList).SelectedItem.Value

            newValues("SeatTypeID") = CType(MyUserControl.FindControl("ddlSeatType"), RadDropDownList).SelectedItem.Value

            newValues("Replacing") = CType(MyUserControl.FindControl("txtReplacing"), TextBox).Text 



                Dim entry As DictionaryEntry

                For Each entry In newValues

                    changedRows(0)(CType(entry.Key, String)) = entry.Value




            Catch ex As Exception


                Dim lblError As Label = New Label()

                lblError.Text = "Unable to update Board Member. Reason: " + ex.Message

                lblError.ForeColor = System.Drawing.Color.Red


                e.Canceled = True

            End Try

        End Sub

  2. Answer
    Konstantin Dikov
    Konstantin Dikov avatar
    2466 posts

    Posted 13 May 2015 Link to this post

    Hi Chris,

    As we have discussed in the support ticket that you have opened (Ticket ID: 933629), the AcceptChanges method is used to update the DataTable object stored in the Session and the underlying database will not be updated. 

    Detailed information on the AcceptChanges method could be found in the following MSDN article:

    Best Regards,
    Konstantin Dikov
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top