This is a migrated thread and some comments may be shown as answers.

Hiding insert form after pressing update link

1 Answer 35 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ceki Granti
Top achievements
Rank 1
Ceki Granti asked on 09 Dec 2008, 11:06 PM
Hi,

I'm trying to edit, insert records via editforms with dataset. After editing records and pressing update, I can change the editmode to false, however I couldn't succeed to do it with inserting records. I searched many topics with examples, forums, help files so on but I couldn't find out the solution. If I use editedItem.Edit=False in insertmode, page gives me  error as "insert item is available only when grid is in insert mode". However its working with editmode.. (I'm not using custom edit form)

Thank you for your help.

I have code like below (To keep it simple, I'm giving the necessary parts of aspx code):

<

 

telerik:RadGrid ID="RadGrid1" runat="server" AllowMultiRowEdit="True" AllowMultiRowSelection="True"

 

 

AutoGenerateColumns="False" OnNeedDataSource="RadGrid1_NeedDataSource" GridLines="None" Skin="Vista" Style="z-index: 148; left: 24px; position: absolute; top: 376px" Width="748px" AllowAutomaticDeletes="True" AllowAutomaticInserts="True" AllowAutomaticUpdates="True" AutoGenerateDeleteColumn="True" AutoGenerateEditColumn="True">

 

 

<MasterTableView DataKeyNames="TeknikServisIslemId" CommandItemDisplay="Top" EditMode="EditForms">

 

Dim

 

taTeknikServis As New dsCrmTableAdapters.TeknikServisTableAdapter

 

 

Dim taTeknikServisDetay As New dsCrmTableAdapters.TeknikServis_DetayTableAdapter

 

 

Dim taTeknikServisYapilanIslemler As New dsCrmTableAdapters.TeknikServis_YapilanIslemlerTableAdapter

 

 

Dim dvTeknikServis, dvTeknikServisYapilanIslemler As DataView

 

 

Dim mRow As DataRowView

 

 


Protected
Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

 

 

If Not Page.IsPostBack Then

 

 

 

 

taTeknikServis.FillByTeknikServisId(ds.Tables(

"TeknikServis"), Request.Params("Id"))

 

taTeknikServisYapilanIslemler.FillByTeknikServisId(ds.Tables(

"TeknikServis_YapilanIslemler"), Request.Params("Id"))

 

 

End If

 

 

 

 

 

If Request.Params("Id") = 0 Then

 

 

 

 

dvTeknikServis =

New DataView(ds.Tables("TeknikServis"))

 

mRow =

CType(dvTeknikServis.AddNew, DataRowView)

 

 

Else

 

 

 

 

dvTeknikServis =

New DataView(ds.Tables("TeknikServis"))

 

mRow =

CType(dvTeknikServis(0), DataRowView)

 

 

End If

 

 

 

 

dvTeknikServisYapilanIslemler = mRow.CreateChildView(

"FK_TeknikServis_YapilanIslemler_TeknikServis")

 

SetControlsText()

 

End Sub

 

Private

 

ReadOnly Property ds() As DataSet

 

 

Get

 

 

 

 

 

Dim obj As Object = Me.ViewState("_Dataset")

 

 

If (Not (obj) Is Nothing) Then

 

 

 

 

 

Return CType(obj, DataSet)

 

 

Else

 

 

 

 

 

Dim mdsCrm As New dsCrm

 

 

Me.ViewState("_Dataset") = mdsCrm

 

 

Return mdsCrm

 

 

End If

 

 

 

 

 

End Get

 

 

 

 

 

End Property


 

Protected

 

Sub RadGrid1_NeedDataSource(ByVal source As Object, ByVal e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles RadGrid1.NeedDataSource

 

RadGrid1.DataSource = dvTeknikServisYapilanIslemler

 

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 editMngr As GridEditManager = editedItem.EditManager

 

 

Dim column As GridColumn

 

 

Dim changedRow As DataRow = dvTeknikServisYapilanIslemler.Item(editedItem.ItemIndex).Row

 

changedRow.BeginEdit()

 

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 = editMngr.GetColumnEditor(editableCol)

 

 

Dim editorType As String = CType(editor, Object).ToString()

 

 

Dim editorText As String = ""

 

 

 

 

 

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

 

 

 

 

changedRow(column.UniqueName) = IIf(editorValue =

"", System.DBNull.Value, editorValue)

 

 

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

 

 

 

 

changedRow.EndEdit()

editedItem.Edit =

False

 

 

 

 

 

 

 

 

End Sub

 

 

 

 

 



Private
Sub RadGrid1_InsertCommand(ByVal source As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles RadGrid1.InsertCommand

 

 

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

 

 

Dim editMngr As GridEditManager = editedItem.EditManager

 

 

Dim newRow As DataRowView = dvTeknikServisYapilanIslemler.AddNew

 

 

For Each column As GridColumn In e.Item.OwnerTableView.RenderColumns

 

 

If TypeOf column Is IGridEditableColumn Then

 

 

 

 

 

Dim editableCol As IGridEditableColumn = (CType(column, IGridEditableColumn))

 

 

If editableCol.IsEditable Then

 

 

 

 

 

Dim editor As IGridColumnEditor = editMngr.GetColumnEditor(editableCol)

 

 

Dim editorText As String = ""

 

 

 

 

 

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

 

 

 

 

 

If column.UniqueName <> "TeknikServisId" Then

 

 

 

 

newRow(column.UniqueName) = IIf(editorValue =

"", System.DBNull.Value, editorValue)

 

 

End If

 

 

 

 

 

Catch ex As Exception

 

RadGrid1.Controls.Add(

New LiteralControl("Unable to insert. Reason: " + ex.Message))

 

e.Canceled =

True

 

 

 

 

 

End Try

 

 

 

 

 

End If

 

 

 

 

 

End If

 

 

 

 

 

Next

 

 

 

 

newRow.EndEdit()

editedItem.Edit =

False '*****If I hide this line, code does not return any error, but it resides to show adding mode*******

 

 

 

 

RadGrid1.Rebind()

 

End Sub

 

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 10 Dec 2008, 04:09 AM
Hello Ceki Granti,

The insert form will not close automatically after inserting, if you set the automatic operations to true i.e., AllowAutomaticInserts, AllowAutomaticUpdates properties to true, when you are actually performing manual operations. So try setting these properties to false.

Thanks
Princy.

Tags
Grid
Asked by
Ceki Granti
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or