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

10 posts, 1 answers
  1. taeho
    taeho avatar
    29 posts
    Member since:
    Mar 2008

    Posted 22 Apr 2008 Link to this post

    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

  2. Answer
    Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 22 Apr 2008 Link to this post

    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
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Xcalibur
    Xcalibur avatar
    11 posts
    Member since:
    Jul 2007

    Posted 28 Jul 2008 Link to this post

    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
  5. Xcalibur
    Xcalibur avatar
    11 posts
    Member since:
    Jul 2007

    Posted 28 Jul 2008 Link to this post

    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
  6. Iana Tsolova
    Admin
    Iana Tsolova avatar
    3388 posts

    Posted 28 Jul 2008 Link to this post

    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.
  7. Xcalibur
    Xcalibur avatar
    11 posts
    Member since:
    Jul 2007

    Posted 28 Jul 2008 Link to this post

    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
  8. Iana Tsolova
    Admin
    Iana Tsolova avatar
    3388 posts

    Posted 29 Jul 2008 Link to this post

    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.
  9. Xcalibur
    Xcalibur avatar
    11 posts
    Member since:
    Jul 2007

    Posted 06 Aug 2008 Link to this post

    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
  10. Paulette Eimer
    Paulette Eimer avatar
    15 posts
    Member since:
    Jun 2008

    Posted 15 Oct 2008 Link to this post

    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
  11. Yavor
    Admin
    Yavor avatar
    11 posts

    Posted 16 Oct 2008 Link to this post

    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.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017