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

Edit after CommandItem insert

1 Answer 50 Views
Grid
This is a migrated thread and some comments may be shown as answers.
John
Top achievements
Rank 1
John asked on 23 Feb 2011, 03:49 PM
I have a hierarchical(or however its spelled) grid, a master(account), first detail(contact) second detail(phone numbers).  On the detail grids i have added command items to allow the user to add new contacts to a account or phone numbers to a contact.  I also have an edit button in the grid so they can change current values. 

I'm using the EditForm Template in a PopUp edit mode, when i click the Add new button in the Command Item i get the InitInsert name in ItemCommand and in item databound the grid is in edit mode, since it uses the same form for edit and insert i show and hide different fields on data bound, if its editing or inserting, i also change the command name of the button on the form so i know what to do when the user clicks it (insertContact, UpdateContact, etc..) On Insert everything works, the proper fields are displayed the proper command name gets passed back to the ItemCommand event, however on Edit the display works (only the editable fields are shown) and in ItemDataBound the grid is in edit mode, the popup shows.  When i click the edit button the popup shows and when i click the update button ItemCommand still fires and i get the UpdateContact command name, but the grid is no longer in edit mode.  I cant find a way to access the controls that were in the edit form popup since the event args in ItemCommand is a GridDataItem and not a GridEditFormItem like it is on an Insert.

Basically i need to know if i can share the same form for Edits and Inserts(since i dont seem to have a choice), and how can i get to the controls on the edit form from the ItemCommand event if e.Item isnt a GridEditFormItem.  I've checked a lot of the help documentation, but cant seem to find a way to accomplish what i need to do.


EDIT:
The problem appears to be caused by me changing the CommandName of the button for an Edit.  If you leave(or set) the CommandName as "Update" everything works correctly in the ItemCommand Event.  I just put a flag in the CommandArgument property to figure out which update code i should run.

Wish there was a better way like EditForm and InsertForm templates to keep everything seperate, and not have to have code in ItemCommand and ItemDataBound to hide and show bits but oh well. 
/EDIT

1 Answer, 1 is accepted

Sort by
0
Mira
Telerik team
answered on 28 Feb 2011, 04:54 PM
Hello John,

I recommend that you examine the following help topic to see how the desired functionality can be implemented:
Switching the Insert/Update/Regular Modes
Updating values using UserControl/FormTemplate
Different edit forms on edit and insert

Please let is know if any further assistance is required.

Greetings,
Mira
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
Tags
Grid
Asked by
John
Top achievements
Rank 1
Answers by
Mira
Telerik team
Share this question
or