Nested grid insert

4 posts, 0 answers
  1. Marcin
    Marcin avatar
    4 posts
    Member since:
    Oct 2012

    Posted 10 Feb Link to this post

    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?

  2. Viktor Tachev
    Admin
    Viktor Tachev avatar
    1488 posts

    Posted 15 Feb Link to this post

    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
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Marcin
    Marcin avatar
    4 posts
    Member since:
    Oct 2012

    Posted 23 Feb Link to this post

    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.

     

  5. Viktor Tachev
    Admin
    Viktor Tachev avatar
    1488 posts

    Posted 26 Feb Link to this post

    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
Back to Top