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
conn.Open()
Try
adapter.Fill(table1)
Finally
conn.Close()
End Try
Return table1
End Function
Public ReadOnly Property Members() As DataTable
Get
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
Me.rgMember.MasterTableView.Rebind()
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
Return
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
changedRows(0).BeginEdit()
Try
Dim entry As DictionaryEntry
For Each entry In newValues
changedRows(0)(CType(entry.Key, String)) = entry.Value
Next
changedRows(0).EndEdit()
Me.Members.AcceptChanges()
Catch ex As Exception
changedRows(0).CancelEdit()
Dim lblError As Label = New Label()
lblError.Text = "Unable to update Board Member. Reason: " + ex.Message
lblError.ForeColor = System.Drawing.Color.Red
rgMember.Controls.Add(lblError)
e.Canceled = True
End Try
End Sub