Here's my setup: I have a MasterPage that has a webform with a RadGrid in it. That RadGrid has one nested table. I'm trying to insert a new item into that nested table using a WebUserControl (ascx) page as the EditForm for the nested Grid.
I've read the help at: http://www.telerik.com/help/aspnet-ajax/grdextractprimarykeyforparentiteminhierarchyonupdateinsert.html
My grid and nested grid are setup pretty much identically to what is there, except that I'm using a MasterPage and usercontrol for the form and I have a dataobject for the datasource.
When updating the nested grid with the usercontrol, the world is a wonderful place and things work just fine. However, when that same form is used for inserting, the binding values go away. In the customers and orders example, the customerID is not set to the default for the primarykey of the parent item.
I tried the code from http://www.telerik.com/help/aspnet-ajax/grdcustomeditforms.html for accessing the grid edited item from the usercontrol.
| GridEditableItem editedItem = this.Parent.NamingContainer; |
It generates a compiler error (cannot implictly convert system.web.ui.control to telerik.web.ui.GridEditableItem. An explict conversion exists). When I explictly cast, editedItem.KeyValues is null. I think this may be something funky with the masterpages.
If parentID is an int32, I can use the following code in the main aspx code behind to get the appropriate value:
| public int parentID {get; set;} if (e.CommandName == RadGrid.InitInsertCommandName) |
| { |
| if (e.Item.OwnerTableView.DataSourceID == "OrderLookup") |
| { |
| GridDataItem parentItem = (GridDataItem)(e.Item.OwnerTableView.ParentItem); |
| if (parentItem != null) |
| { |
| parentID = (Convert.ToInt32((parentItem.OwnerTableView.DataKeyValues[parentItem.ItemIndex]["CustomerID"]))); |
| } |
| } |
| } |
But I can not for the life of me access that value from the ascx page. I'm also assuming this is because of some masterpage stuff that I haven't figured out yet.
So, How can I reference that DataKeyValue from the WebUserControl for an insert function? I need to set the default value for the customerID. What is the best way to accomplish this?