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

User Control edit form change from insert to edit mode on control event

1 Answer 135 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Chris
Top achievements
Rank 2
Chris asked on 07 Jan 2009, 09:00 AM
Hi,
 I am have a UserControl I am using to edit / create records in a RadGrid. This control has a child rad grid in it that will allow users to add / modify related items. These child items need a reference to the parent object (this will be an ID column in the releveant database table).  There is no problem when the parent record already exsists( as i have the parent record ID to use in the child ecord insert) but when i add a new record and the user control is in insert mode there is no ID available. What I want to be able to do is  trigger the creation of the parent record, retreive the parent record ID and keep the usercontrol open but now in edit mode so that the child grid can be filled in.  The creation of the parent record wopuld be on a control event (dropdownlist.slectedindexchanged for example).

The effect I am looking for is as if I did the following actions;

1. add new parent record and fill in data
2. Click insert button and commit parent record to database (thereby creating the parent records ID)
3. Open the parent record for edit
4. add items to child grid (databound to SQL Datasource)

The only other option I can think of is to add records to the grid and then pass back to the parent record creation routine, but i'm not sure how to set up a radgrid to do this.

Thanks in advance for any help you can give me.

Chris

1 Answer, 1 is accepted

Sort by
0
Sebastian
Telerik team
answered on 10 Jan 2009, 09:46 AM
Hello Chris,

Thank you for the detailed explanation.

After you insert a new record in the main grid (either using automatic or manual inserts), you can use the @@Identity or Scope_Identity to return the key field of the newly inserted item. Once you get it, you can traverse the rows in the grid in order to find that to which this key value corresponds, set its Edit property to true and refresh the control invoking its Rebind() method. This can take place inside the PreRender event of the grid for example.

Thus the newly injected record should be directly switched in edit mode and you can pass its id to the child grid inside the WebUserControl edit form.

Best regards,
Sebastian
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Grid
Asked by
Chris
Top achievements
Rank 2
Answers by
Sebastian
Telerik team
Share this question
or