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

Nested grid insert

3 Answers 132 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Marcin
Top achievements
Rank 1
Marcin asked on 10 Feb 2016, 02:42 PM

Hello...

I have a radgrid1 (the parent) which allows you to insert records with a formtemplate.

 inside radgrid1's form template i have another radgrid (radgrid2) which basically is a child of radgrid one.... think of radgrid1 as a cars, and radgrid 2 as carparts.... so i want to insert a honda.... but as part of honda i want to add engine, seats etc.

 

my problem is i'm not sure how to approach a scenario where i click "add new record" on radgrid1... my formtemplate pops up... but because performinsert hasn't been called yet.... i can't add items to my radgrid2 since the parent doesnt have a datakeyvalue yet as parent record not inserted yet.

 

How would you go about this?  how would i databind the child grid when i'm still trying to add the parent?

3 Answers, 1 is accepted

Sort by
0
Viktor Tachev
Telerik team
answered on 15 Feb 2016, 09:50 AM
Hello Marcin,

As I understand the scenario you have a custom insert form. It is used to enter data for both the parent and nested GridTableView.

If this is the case you can use custom logic in the code-behind and add the data directly to the data source. You can use the OnInsertCommand event of RadGrid for this. In the handler you can access the data source and add the new information.

By default the RadGrid control is automatically rebound after the InsertCommand event. Thus, the new data should be visible in the grid.

Check out the following resources that describe in more detail how you can manually update the data:



Regards,
Viktor Tachev
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Marcin
Top achievements
Rank 1
answered on 23 Feb 2016, 08:08 PM

Sorry i was away on vacation

 

I have a Parent grid (radgrid1) which uses a modal popup template.... within that form template i have another child radgrid (radgrid2) which needs to be bound to sql with needs the value from radgrid 1 for its foreign key (primary/foreign key relationship).

 

What i don't understand still is when i hit add new record on ragrid1, then immediately hit add new record on my radgrid2 fill out most basic info for radgrid2 and hit its save button for radgrid2(the child grid) there is no value from radgrid1 yet as that record has not been created yet. the oninsertcommand event you talk about, would refer to radgrid1 or 2? the grids have seperate datasources in which 2 depends on 1, including at the time of insertion.

 

0
Viktor Tachev
Telerik team
answered on 26 Feb 2016, 12:47 PM
Hello  Marcin,

In order to insert data in the detail data source there should be a parent item that the data is related to first. Thus, by default you would need to insert an item in the master grid first and update the details for that item afterwards.

If you would like to change that behavior you would need to implement custom EditForm and custom logic for updating. When updating the item, in the code behind you should add the master item to the corresponding data source and also update the details in the other database table manually.


Regards,
Viktor Tachev
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
Grid
Asked by
Marcin
Top achievements
Rank 1
Answers by
Viktor Tachev
Telerik team
Marcin
Top achievements
Rank 1
Share this question
or