Hi,
I am having a problem with adding new child records. The problem is linking these child records to their parent. I am binding my whd to a generic list of objects, each of which may have child objects.
In the child object, I have a property called ParentID, which allows me to link exisitng child rows/objects to the parent rows/objects. However, the property is empty for new rows. I cant think of anything I can utilize in the row_adding event for the child row.
Hey Marshal,
So, do all child rows have the same ParentId. So if a root row had Id of 5, and it had 3 child rows, all those rows have ParentId of 5, too? And you want the new row to have that same value? Try this code for you client row adding event.
function rowAdding(grid, args) { var parentRow = grid.get_parentRow(); var cellVals = args.get_cellValues(); for (var x = 0; x < cellVals.length; ++x) { if (cellVals[x].DataKeyField == "ParentId") args.get_cellValues()[x].Value = parentRow.get_cellByColumnKey("Id").get_text(); } }
-Dave
Hi David,
Thanks for your reply. I do have a column for the Parent ID in my child row. That is how I am able to update the child row. But for the new rows, this Parent ID is empty. It only has the ID for existing child rows. If you had tried the methods you described successfully, could you please outline the steps?
Best,
Marshal
Hi vimaljonn,
I can think of two approaches, one of which I have tried. The first is to have a column in your child grids for the parent Id value. You can hide this column and in the row adding client event, simply set it to the correct value. Then you should be fine.
Another option would be to handle the row adding server event and try adding another key/value pair to eventArgs.Values. This would contain your ParentId / val.
Let us know if you need more help.
regards,David Young