I'm try the telerik component 2008 Q2. i'm using vs2005. i try from the example of telerik, which is RadGrid -> Insert/Update/Delete -> Extracting Values -> Using Column Editor. i never can to updating data, even when i try to update data from the telerik example. the data only update on the web, but when i close the browser and load the example again, the data back to normal (no changes). this happen also in my project. i already follow all the instruction from the example, but still can't update the data. is there something missing?
here my aspx code:
<
telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
<AjaxSettings>
<telerik:AjaxSetting AjaxControlID="RadGrid1">
<UpdatedControls>
<telerik:AjaxUpdatedControl ControlID="RadGrid1" />
</UpdatedControls>
</telerik:AjaxSetting>
</AjaxSettings>
</telerik:RadAjaxManager>
<telerik:RadGrid ID="RadGrid1" Skin="Default" runat="server" Width="45%" GridLines="None"
AutoGenerateColumns="False" PageSize="10" AllowSorting="True" AllowPaging="True"
ShowStatusBar="true">
<PagerStyle Mode="NumericPages"></PagerStyle>
<MasterTableView DataKeyNames="id_divisi" AllowMultiColumnSorting="True" Width="100%"
CommandItemDisplay="Top">
<Columns>
<telerik:GridButtonColumn UniqueName="DeleteColumn" Text="Delete" CommandName="Delete" />
<telerik:GridEditCommandColumn UpdateText="Update" UniqueName="EditCommandColumn"
CancelText="Cancel" EditText="Edit">
<HeaderStyle Width="45px"></HeaderStyle>
</telerik:GridEditCommandColumn>
<telerik:GridBoundColumn UniqueName="nama_divisi" SortExpression="nama_divisi" HeaderText="Nama Divisi"
DataField="nama_divisi" />
<telerik:GridBoundColumn UniqueName="keterangan" SortExpression="keterangan" HeaderText="Keterangan"
DataField="keterangan" />
</Columns>
<EditFormSettings CaptionFormatString="Edit Divisi ID {0}" CaptionDataField="id_divisi">
<FormTableItemStyle Width="100%" Height="29px"></FormTableItemStyle>
<FormTableStyle GridLines="None" CellSpacing="0" CellPadding="2"></FormTableStyle>
<FormStyle Width="100%" BackColor="#eef2ea"></FormStyle>
<EditColumn ButtonType="ImageButton" />
</EditFormSettings>
</MasterTableView>
</telerik:RadGrid>
and this is my code behind:
Partial
Class Master_divisi
Inherits System.Web.UI.Page
Dim cs As String = ConfigurationManager.ConnectionStrings("CsTs").ConnectionString
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
RadGrid1.MasterTableView.EditMode = GridEditMode.EditForms
End If
End Sub
Public ReadOnly Property DivisiData() As DataSet
Get
Dim obj As Object = Me.Session("DivisiData")
If Not obj Is Nothing Then
Return CType(obj, DataSet)
End If
Dim MyDivisiData As DataSet = New DataSet
Dim ConnString As String = cs
Dim conn As SqlConnection = New SqlConnection(ConnString)
Dim adapter As SqlDataAdapter = New SqlDataAdapter
adapter.SelectCommand =
New SqlCommand("SELECT id_divisi, nama_divisi, keterangan FROM tbl_divisi", conn)
adapter.Fill(MyDivisiData,
"tbl_divisi")
Me.Session("DivisiData") = MyDivisiData
Return MyDivisiData
End Get
End Property
Protected Sub RadGrid1_NeedDataSource(ByVal source As Object, ByVal e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles RadGrid1.NeedDataSource
RadGrid1.DataSource =
Me.DivisiData
Me.DivisiData.Tables("tbl_divisi").PrimaryKey = New DataColumn() {Me.DivisiData.Tables("tbl_divisi").Columns("id_divisi")}
End Sub
Private Sub RadGrid1_UpdateCommand(ByVal source As System.Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles RadGrid1.UpdateCommand
Dim editedItem As GridEditableItem = CType(e.Item, GridEditableItem)
Dim editMan As GridEditManager = editedItem.EditManager
Dim column As GridColumn
For Each column In e.Item.OwnerTableView.Columns
If TypeOf column Is IGridEditableColumn Then
Dim editableCol As IGridEditableColumn = CType(column, IGridEditableColumn)
If (editableCol.IsEditable) Then
Dim editor As IGridColumnEditor = editMan.GetColumnEditor(editableCol)
Dim editorType As String = CType(editor, Object).ToString()
Dim editorText As String = "unknown"
Dim editorValue As Object = Nothing
If (TypeOf editor Is GridTextColumnEditor) Then
editorText =
CType(editor, GridTextColumnEditor).Text
editorValue =
CType(editor, GridTextColumnEditor).Text
End If
If (TypeOf editor Is GridBoolColumnEditor) Then
editorText =
CType(editor, GridBoolColumnEditor).Value.ToString()
editorValue =
CType(editor, GridBoolColumnEditor).Value
End If
If (TypeOf editor Is GridDropDownColumnEditor) Then
editorText =
CType(editor, GridDropDownColumnEditor).SelectedText & "; " & CType(editor, GridDropDownColumnEditor).SelectedValue
editorValue =
CType(editor, GridDropDownColumnEditor).SelectedValue
End If
Try
Dim changedRows As DataRow() = Me.DivisiData.Tables("tbl_divisi").Select("id_divisi = " & editedItem.OwnerTableView.DataKeyValues(editedItem.ItemIndex)("id_divisi"))
changedRows(0)(column.UniqueName) = editorValue
Me.DivisiData.Tables("tbl_divisi").AcceptChanges()
Catch ex As Exception
RadGrid1.Controls.Add(
New LiteralControl("<strong>Unable to set value of column '" & column.UniqueName & "'</strong> - " + ex.Message))
e.Canceled =
True
End Try
End If
End If
Next
RadGrid1.MasterTableView.Rebind()
End Sub
Protected Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRender
If Not MyBase.IsPostBack Then
Me.RadGrid1.MasterTableView.Rebind()
End If
End Sub
End
Class
Please help me.
thanks
peper