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

related grid, getting a selected datakey from the first grid when inserting in the second grid

9 Answers 156 Views
Grid
This is a migrated thread and some comments may be shown as answers.
taeho
Top achievements
Rank 1
taeho asked on 22 Apr 2008, 05:38 AM
I have two related grids... something like 
http://www.telerik.com/demos/aspnet/Grid/Examples/Programming/SelectedValue/DefaultCS.aspx

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.

protected

void Order_InsertCommand(object source, GridCommandEventArgs e)
{
GridEditableItem editedItem = e.Item as GridEditableItem;
Hashtable newValues = new Hashtable();
e.Item.OwnerTableView.ExtractValuesFromItem(newValues, editedItem);
// get the selected customerID from the first grid...

}

Thank you in advance

9 Answers, 1 is accepted

Sort by
0
Accepted
Vlad
Telerik team
answered on 22 Apr 2008, 06:53 AM
Hi taeho,

You can use SelectedValue property of the first grid to achieve this.

Greetings,
Vlad
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Xcalibur
Top achievements
Rank 1
answered on 28 Jul 2008, 07:29 AM
Vlad i am having the same problem and it is a real showstopper for me.  Let me explain the scenario as i think it is the same as taeho ...

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
0
Xcalibur
Top achievements
Rank 1
answered on 28 Jul 2008, 07:50 AM
UPDATE: I just retried using pure SqlDataSources pointing to stored procedures to remove the possibility of .netTiers causing the issue and i am having the same problem - basically insertion is failing as PatientID is passed across as null.

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.

Cheers
0
Iana Tsolova
Telerik team
answered on 28 Jul 2008, 02:46 PM
Hello Xcalibur,

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/DEMOS/ASPNET/Prometheus/Grid/Examples/DataEditing/AllEditableColumns/DefaultCS.aspx
http://www.telerik.com/DEMOS/ASPNET/Prometheus/Grid/Examples/DataEditing/TemplateFormUpdate/DefaultCS.aspx
http://www.telerik.com/help/aspnet-ajax/grdinsertingvaluesinplaceandeditforms.html (here you can find how to change the default field values on InitInsertCommand)
http://www.telerik.com/help/aspnet-ajax/grdinsertingvaluesusercontrolformtemplate.html

Give this suggestions a try and let us know how it goes.

Best wishes,
Iana
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Xcalibur
Top achievements
Rank 1
answered on 29 Jul 2008, 02:51 AM
Iana

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
0
Iana Tsolova
Telerik team
answered on 29 Jul 2008, 10:35 AM
Hello Xcalibur,

Please find the attached sample implementing the desired functionality. Try it on your end and let me know if any issues arise.

I hope this helps.

Regards,
Iana
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Xcalibur
Top achievements
Rank 1
answered on 06 Aug 2008, 04:40 PM
Just to tie up this thread, i have found this is an 'issue' of .netTiers.  Since it doesnt allow individual Insert/Select/Update parameters, it is impossible to implement the solution you provided me, hence i was forced to revert to using a standard SqlDataSource and it worked fine.  This could very well be a lack of knowledge on my part in using the .netTiers typed data sources as their documentation is quite lacking.  Either way thank you for your help
0
Paulette Eimer
Top achievements
Rank 2
answered on 15 Oct 2008, 05:35 PM
My exact problem. I downloaded the last example but there wasn't any code in the code behind!

So I'm still hunting for a solution.

Tried searching again but kept getting a server error message.

I'll keep trying.

Paulette
0
Yavor
Telerik team
answered on 16 Oct 2008, 05:26 AM
Hi Paulette,

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.

Greetings,
Yavor
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Grid
Asked by
taeho
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Xcalibur
Top achievements
Rank 1
Iana Tsolova
Telerik team
Paulette Eimer
Top achievements
Rank 2
Yavor
Telerik team
Share this question
or