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

How to clear the EditForm (Insert)

8 Answers 197 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Robert
Top achievements
Rank 1
Robert asked on 04 May 2012, 09:34 PM
I am have a RadGrid and use EditForms with a template.  I allow inserts and edits and I am having a problem with clearning the EditForm when a user clicks to edit a row.  When I click on the Add New link it shows an empty template and that is perfect but If I then choose to then click Edit on an existing row it creates another edit form in edit mode.  So now I have 2 edit forms 1 for a new record and 1 an edit to a record.  Since I have validation on my edit forms submitting either form causes validation to fire on both. 

I know that I can clear edit items when I click the add new link such as:

Protected Sub RadGrid1_ItemCommand(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles RadGrid1.ItemCommand
  Select Case e.CommandName
    Case RadGrid.InitInsertCommandName
      ' cancel any previous edits
      RadGrid1.MasterTableView.ClearEditItems()
    Case RadGrid.EditCommandName
  End Select
End Sub

This works fine clearing out edits but not inserts.  How can I clear the insert items when I choose to edit a row in the grid since there seems to be no .ClearInsertItems() method?

8 Answers, 1 is accepted

Sort by
0
Elliott
Top achievements
Rank 2
answered on 04 May 2012, 09:59 PM
Robert - what I think you are trying to do is to issue a Cancel to the Edit or the Insert, right?
I would approach your need that way - I have done a CancelAll in a script
0
Robert
Top achievements
Rank 1
answered on 04 May 2012, 10:07 PM
Well sort of... I am trying to make sure the user is only performing 1 insert or 1 edit at any given time.  I can easily cancel edits but I cannot cancel the inserts.
0
Elliott
Top achievements
Rank 2
answered on 07 May 2012, 03:53 PM
now I am confused - when I edit one row the row already open for edit closes
how can you have more than one row open for edit at any one time?
0
Robert
Top achievements
Rank 1
answered on 07 May 2012, 03:56 PM
This prevents that from happening.
Remove this and you can open every row for edit: RadGrid1.MasterTableView.ClearEditItems()

Protected Sub RadGrid1_ItemCommand(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles RadGrid1.ItemCommand
  Select Case e.CommandName
    Case RadGrid.InitInsertCommandName
      ' cancel any previous edits
      RadGrid1.MasterTableView.ClearEditItems()
    Case RadGrid.EditCommandName
  End Select
End Sub

The point is that I do not want more than 1 row open for editting / adding at any time. This is because I use validation.  If I have more than 1 row open the validation fires for all of the rows being added/editted.
0
Elliott
Top achievements
Rank 2
answered on 07 May 2012, 04:37 PM
I can't help you any more
could someone i.e. MVP or Telerik Admin jump in and straighten things  out here?
0
Robert
Top achievements
Rank 1
answered on 07 May 2012, 04:43 PM
As a work around I can cancel the edit on the Item_Command event handler:

Not the behavior I want but so far it will have to kludge what should be a obvious behavior. 

 

If RadGrid1.MasterTableView.IsItemInserted Then

 

    e.Canceled =

True

 

 

End If

Adding this to the grid didn't prevent an add and an edit from occurring at the same time either:

 

  AllowMultiRowEdit="false"
  AllowMultiRowSelection="false" 
0
Accepted
Antonio Stoilkov
Telerik team
answered on 09 May 2012, 07:32 AM
Hello Robert,

You could achieve your scenario by following the steps described below:
  • Subscribe to RadGrid ItemCommand event
  • Use the code provided below. Note that the difference is the a condition for EditCommandName which closes the insert item by setting the IsItemInserted to false
Protected Sub RadGrid1_ItemCommand(sender As Object, e As Telerik.Web.UI.GridCommandEventArgs)
    If e.CommandName = RadGrid.EditCommandName Then
        Me.RadGrid1.MasterTableView.IsItemInserted = False
    ElseIf e.CommandName = RadGrid.InitInsertCommandName Then
        Me.RadGrid1.MasterTableView.ClearEditItems()
    End If
End Sub

Regards,
Antonio Stoilkov
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Robert
Top achievements
Rank 1
answered on 09 May 2012, 01:31 PM
Thanks Antonio... exactly what I needed.

I would think the control should behave this way by design.
Tags
Grid
Asked by
Robert
Top achievements
Rank 1
Answers by
Elliott
Top achievements
Rank 2
Robert
Top achievements
Rank 1
Antonio Stoilkov
Telerik team
Share this question
or