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

Update Parent Rows after Child Row Updated

4 Answers 104 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Sean
Top achievements
Rank 1
Sean asked on 07 Sep 2008, 08:22 PM
Hi,
I have a project where in a RadGrid the Master Table rows contain template columns that display totals based values in the Child detail table. The user is able to Update the Detail table rows which would affect the totals given in the parent row. However, when the user does update a record, the parent row doesn't update until I reload the page. How can I use the update event to also rebind the parent row?

I currently have a SQLDataSource object for each of the Parent and Child tables. Is there a relatively easy way to get the Parent Row to rebind on update since I shouldn't need to rebind all rows in the parent?

Currently, I have only written a RadGrid1_UpdateCommand and RadGrid1_ItemDataBound.

protected void RadGrid1_UpdateCommand(object source, GridCommandEventArgs e) 
    //Get the GridEditableItem of the RadGrid      
    GridEditableItem editedItem = e.Item as GridEditableItem; 
 
    //Get the Primary Key associated with the edited row 
 
    //Get the Control Values for the associated rows 
 
    //Insert and update soem information in the database             
 
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
    if (e.Item is GridDataItem && e.Item.OwnerTableView.DataSourceID == "SQLDataSourceParent"
    { 
         //Get the GridEditableItem of the RadGrid      
        GridDataItem dataItem = e.Item as GridDataItem; 
                 
        //Get the primary key value of the row using the DataKeyValue.      
                 
        //Set the Template Column values based on database records 
    } 

4 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 1
answered on 08 Sep 2008, 04:29 AM
Hello Sean,

Can you try rebinding the MasterTableView explicitly after you update the child table as shown in the code below.
RadGrid1.MasterTableView.Rebind(); 

Thanks
Princy.
0
Sean
Top achievements
Rank 1
answered on 08 Sep 2008, 02:17 PM
Hi Princy,

I tried to do a Rebind() as the last call in RadGrid1_UpdateCommand(). The Master Table rebinds but the child item stays in Edit Mode.

I ended up getting the Parent Row GridDataItem, GridTableView, and Parent ItemIndex. I then get the Primary Key for the parent Row and the Label Control. Then running the method that updates the template column label. Seems to work.

I may (will) run into problems later where users are updating the database at the same time and the information isn't updateed in the rest of the table.

Sean
0
Roger
Top achievements
Rank 1
Veteran
answered on 07 Apr 2021, 04:43 PM

Hi

I know this post is already really old, but I had the exactly same problem that child item did open again in edit mode after rebinding the master table.

My solution was as follows (in InsertCommand or UpdateCommand event, editableItem is (GridEditableItem)e.Item):

editableItem.Edit = false; //prevent opening item in edit mode again
var retainExpandStateOnRebindBak = this.UsersGrid.MasterTableView.RetainExpandStateOnRebind;
this.UsersGrid.MasterTableView.RetainExpandStateOnRebind = true;
this.UsersGrid.MasterTableView.Rebind();
this.UsersGrid.MasterTableView.RetainExpandStateOnRebind = retainExpandStateOnRebindBak;

 

Besides the issue with edit mode, I also wanted to keep the details table view expanded after clicking on save.

Cheers,
Roger

0
Attila Antal
Telerik team
answered on 12 Apr 2021, 01:00 PM

Hi Roger,

To be able to help, I would need to see how the data binding and updating logic.

It would be best if you could share the complete RadGrid declaration and the Code behind related to it.

Regards,
Attila Antal
Progress Telerik

Тhe web is about to get a bit better! 

The Progress Hack-For-Good Challenge has started. Learn how to enter and make the web a worthier place: https://progress-worthyweb.devpost.com.

Roger
Top achievements
Rank 1
Veteran
commented on 29 Apr 2021, 06:45 AM

Hi Attila

Thanks for getting involved. The workarounds I posted work for me. If you are interested in my current setup with declarations etc. I can paste it here, but I don't know, how to insert formatted code & HTML in this new forum (this thread has been migrated).

Cheers,
Roger
Roger
Top achievements
Rank 1
Veteran
commented on 29 Apr 2021, 06:46 AM

Ah ok, you can only insert formatted code & HTML, when actually answering (but not in comments).
Attila Antal
Telerik team
commented on 03 May 2021, 04:15 PM

Hi Roger,

Comments work similarly to StackOverflow which cannot be formatted. So you will need to post your message as an Answer.

However, you have a license, and I think it would be best if you open a Formal Support ticket, and there we can investigate the issue together. Once we have figured it out, I can share the resolution in the Forum thread to make it available for the public.

Tags
Grid
Asked by
Sean
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 1
Sean
Top achievements
Rank 1
Roger
Top achievements
Rank 1
Veteran
Attila Antal
Telerik team
Share this question
or