I’m trying to use the RadGrid in a Page with disabled ViewState.
<%@ Page Language="C#" AutoEventWireup="true" EnableViewState="false" … %>
Here’s my scenario:
· My page contains a RadGrid with EditMode="EditForms" and a <rad:GridEditCommandColumn /> column.
· When clicking on this column, the edition starts as it should.
· On the next postback – might be not even due to a grid event – the grid “forgot” is has entered edit mode and the form is not displayed anymore.
I understand the behaviour since I’ve deactivated the ViewState. I’d like to maintain this information in the server in a custom way. My question is how do I hook the grid’s server-side events to tell it that it is in edit mode ?
I’ve found the following example on your community site:
http://www.telerik.com/community/code-library/submission/b311D-tgtkd.aspx
Although this example does not rely on the ViewState for the current data of the grid, it relies on the ViewState for the “edit” mode.
Thanks
public
class FilterPanel : FilterPanelBase {
protected override void OnInit(EventArgs e)
{
FilterPanelTemplate t = new FilterPanelTemplate();
Control myContainer = new Control();
t.InstantiateIn(myContainer);
this.ItemTemplate = t;
base.OnInit(e);
}
}
public
class FilterPanelTemplate : ITemplate
{
public void InstantiateIn(Control container)
{
TextBox _filterInput = new TextBox();
_filterInput.ID =
"_filterInput";
_filterInput.Text =
"Suchbegriff...";
container.Controls.Add(_filterInput);
}
}
It doesn't work.
<
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>
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.

