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:
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?
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
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
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?
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:
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.
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?
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.
Adding this to the grid didn't prevent an add and an edit from occurring at the same time either:
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
Hello Robert,
You could achieve your scenario by following the steps described below:
Regards,
Antonio Stoilkov
the Telerik team
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.
I would think the control should behave this way by design.