I'm having a problem figuring out the correct way to populate an edit form with data when using a master/detail hierarchy.
The problem I'm having is when I show the edit form for a detail item in one hierarchy group the data in any visible edit form in the other hierarchy groups no longer has data so the edit form is empty. I'm using the edit form to display additional, static, information about the detail item.
The way I currently have it setup is to use the ItemDataBound event to check if the item is in edit mode and if it's a GridEditFormItem. From there I can get the DataItem from the item to populate labels in the edit form template. This works fine when showing the edit form for any of the detail rows in the current hierarchy group. However, checking e.Item.IsInEditMode only catches the items in the hierarchy group the expanded item is in. This means the other previously expanded hierarchy group detail rows never get repopulated with data so their form's are blank and introduces my problem.
I tried to update my code to use the ItemCreated event but for the items not in the current hierarchy group both the e.Item.DataItem and the edit form's ParentItem.DataItem are null.
Anyone have any suggestions or other questions that might help me track down the correct way to do this?
5 Answers, 1 is accepted
1. Run the project with the code changes below
2. Click the first > button to expand the "Beverages" category
3. Click the Edit link for "Chai"
4. Notice the edit form has the product name "Chai" showing.
5. With "Chai" expanded still click the second > to expand the "Condiments" category.
6. Notice the product details in the "Chai" edit form are now missing.
Thank you for the detailed clarification. Please try the following sample approach:
the Telerik team
Thank you for your reply. The changes you suggested do work for the example, and make sense, but unfortunately they will not work for me in my production code because I don't know the type, or number, of controls I'll need to create until I look at the detail data.
The way I currently have this working is by using the ItemCreated event and checking to see if the editFormItem.ParentItem.DataItem has an entity. If it is null I'll figure out the ID I need by parsing the editFormItem.KeyValues and doing a new query for the detail data with this ID. This grid is not on a heavily used page, and there won't be many situations where multiple detail rows have their details exposed, but I'm just not sure if the requery for the data is the best way to get to the data I need to add the dynamic controls.
We'll be glad to assist you further if you need additional assistance. In this case you can submit a support ticket with simple working example which will allow us to examine the concrete scenario.
the Telerik team