Now I would like to insert a new records in the second grid and when that happen I need to be able to get the selected customer's id from the first grid (Customer) in the second grid (Order) insert command event.
void Order_InsertCommand(object source, GridCommandEventArgs e)
GridEditableItem editedItem = e.Item as GridEditableItem;
Hashtable newValues = new Hashtable();
// get the selected customerID from the first grid...
Thank you in advance
9 Answers, 1 is accepted
You can use SelectedValue property of the first grid to achieve this.
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
If i add an insert command to the related grids example on your site, it pops up the edit form fine and i can fill everything out, but when i click Insert it crashes because the "ProductID" (for the sake of the explanation) is not specified to the data source (the actual error is SQL server complaining that the specified ProductID does not exist, because there is no entry that is null).
To get around this issue, i tried adding a bound column to the second "Orders" grid view that is readonly so it wont be displayed in the edit form and bound to the ProductID data field, hoping that this would cause it to be passed to the underlying data source of the second table. However this doesnt seem to be the case.
My instinct is that this should be possible purely through the ASPX and not involve any code and that many people must have done this before. Please help me see the obvious!
BTW i am using .netTiers as the back end and its associated object data sources in case this causes any known issues
The essence of what i want to know, forgetting the specifics of my situation, is how would one implement the ability to insert on a related data grid - where the id of the first grid is required for the insert.
As previously mentioned, you could get the first grid id (the "CustomerID") from the grid SelectedValue property. Note that you should add the primary key field for the first grid (the "CustomerID" in our sample) to the DataKeyNames array of its MasterTableView.
Regarding your question about grid insertion:
Please review the following articles on grid update/insert operations:
http://www.telerik.com/help/aspnet-ajax/grdinsertingvaluesinplaceandeditforms.html (here you can find how to change the default field values on InitInsertCommand)
Give this suggestions a try and let us know how it goes.
the Telerik team
Your response is somewhat helpful - but does not completely answer my question. Let me rephrase again for clarity.
What i would like to see, is exactly the 'related grids' demo you have here but with insertion/edit/delete abilities on the second (related) grid (Orders). I have no problems with insertion/edit/delete on a single grid.
Now i understand how the SelectedValue property will give me the value i require, however i am not sure how this needs to be used in the codebehind to insert the value into the new 'row'. The third link you provided seems to be in the right area but i have not figured it out yet and time is limited for me ...
Perhaps you can provide me with an example that is simply the related grid demo + insert/edit/delete on the related grid? This would be most appreciated and judging by the moderately high hits on this thread, useful to many others too
So I'm still hunting for a solution.
Tried searching again but kept getting a server error message.
I'll keep trying.
Do you have the same setup? If the issue persists, and you do not find the answer to the issue in this thread, you can open a formal support ticket, and sent us the code, for additional review.
the Telerik team