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

[Solved] Find key of parent row in hierarchy grid window insert

4 Answers 268 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Laura
Top achievements
Rank 1
Laura asked on 17 Apr 2009, 04:19 AM
I have a 3 level hierarchy level grid which I use rad window popup for edit and insert. I need to send the parent ID of a detail row on insert. For example, I have the parent as provider, and the child as service. When inserting a new service, I need to send it's parent provider ID that it is being inserted under. I have the pop up set up correctly in the itemcreated function here:
 protected void providersGrid_ItemCreated(object sender, Telerik.Web.UI.GridItemEventArgs e) 
    { 
 
        if (e.Item is GridDataItem && e.Item.OwnerTableView.Name == "Master"
        { 
              
                try 
                { 
                    int providerID = Convert.ToInt32(e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["provider_id"]); 
                    ImageButton editLink = (ImageButton)e.Item.FindControl("EditProviderLink"); 
                    if (Session["readonly"].ToString() == "Y"
                    { 
                        editLink.ImageUrl = "Images/viewSpelled.gif"
                        editLink.ToolTip = "View"
 
                    }                      
                    editLink.Attributes["href"] = "#"
                    editLink.Attributes["onclick"] = string.Format("return ShowEditForm('{0}','{1}');", e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["provider_id"], e.Item.ItemIndex); 
                 
 
                } 
                catch (Exception e1) 
                { 
                } 
                try 
                { 
 
                    ImageButton editLink = (ImageButton)e.Item.FindControl("DeleteProviderLink"); 
                    if (Session["readonly"].ToString() == "Y"
                        editLink.Visible = false
                    else 
                    { 
                        editLink.Attributes["href"] = "#"
                        editLink.Attributes["onclick"] = string.Format("return ShowDeleteForm('{0}','{1}');", e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["provider_id"], e.Item.ItemIndex); 
                    } 
 
                } 
                catch (Exception e1) 
                { 
                } 
              
        } 
        if (e.Item is GridDataItem && e.Item.OwnerTableView.Name == "ServiceTableView"
        { 
              
                try 
                { 
 
                    ImageButton editLink = (ImageButton)e.Item.FindControl("EditServiceLink"); 
                   if (Session["readonly"].ToString() == "Y"
                    { 
                        editLink.ImageUrl="Images/viewSpelled.gif"
                        editLink.ToolTip="View"
           
                    } 
                    editLink.Attributes["href"] = "#"
                    int id =Convert.ToInt16( e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["service_id"]); 
 
                    editLink.Attributes["onclick"] = string.Format("return ShowEditServiceForm('{0}','{1}');", e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["service_id"], e.Item.ItemIndex); 
                } 
                catch (Exception e1) 
                { 
                } 
                try 
                { 
 
                    ImageButton editLink = (ImageButton)e.Item.FindControl("DeleteServiceLink"); 
                    if (Session["readonly"].ToString() == "Y"
                        editLink.Visible = false
                    else 
                    { 
                        editLink.Attributes["href"] = "#"
                        editLink.Attributes["onclick"] = string.Format("return ShowDeleteServiceForm('{0}','{1}');", e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["service_id"], e.Item.ItemIndex); 
                    } 
 
                } 
                catch (Exception e1) 
                { 
                } 
              
        } 
 
        if (e.Item is GridDataItem && e.Item.OwnerTableView.Name == "FeedTableView"
        { 
              
                try 
                { 
 
                    ImageButton editLink = (ImageButton)e.Item.FindControl("EditFeedLink"); 
                    if (Session["readonly"].ToString() == "Y"
                    { 
                        editLink.ImageUrl = "Images/viewSpelled.gif"
                        editLink.ToolTip = "View"
                    } 
                    editLink.Attributes["href"] = "#"
                    editLink.Attributes["onclick"] = string.Format("return ShowEditFeedForm('{0}','{1}');", e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["feed_id"], e.Item.ItemIndex); 
                 } 
                catch (Exception e1) 
                { 
                } 
                try 
                { 
 
                    ImageButton editLink = (ImageButton)e.Item.FindControl("DeleteFeedLink"); 
                    if (Session["readonly"].ToString() == "Y"
                        editLink.Visible = false
                    else 
                    { 
                        editLink.Attributes["href"] = "#"
                        editLink.Attributes["onclick"] = string.Format("return ShowDeleteFeedForm('{0}','{1}');", e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["feed_id"], e.Item.ItemIndex); 
                    } 
                } 
                catch (Exception e1) 
                { 
                } 
            } 
          
         
    } 

And I call the pop up from here but the ID is not set correctly ( will show how i set it and why it is wrong after this code:
function ShowInsertServiceForm() { 
             // get username from querystring to pass to next window 
             var urlArgs = cbeGetURLArguments(); 
             var userName = urlArgs.NAME; 
             var sync = urlArgs.SYNC; 
 
             var providerIDTxtBx = document.getElementById("currentProviderID"); 
             var pID = providerIDTxtBx.value; 
 
             var oWnd = window.radopen("editServiceForm.aspx?SYNC=" + sync + "&NAME=" + userName + "&pID=" + pID, "providerDialog"); 
 
             //set a function to be called when RadWindow is closed 
             oWnd.add_close(OnClientServiceClose); 
             var oArg = new Object(); 
 
             oArg.serviceID = -99; 
 
             //set the arguments that will be needed on the way back so they are not undefined 
             oWnd.argument = oArg; 
             return false
         } 
I set the ID (currentProviderID) in a textbox when the provider is expanded. I set it in the itemcommand onhierarchyexpanded, but it is not right, since the user can expand a number of different providers, and not insert a new service in the LAST exanded provider. So my question is, where do I capture the providerID (or serviceID for a feed - 3rd level down) before calling the radopen so that I can send the providerID in the querystring?

Thanks,
Laura

4 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 17 Apr 2009, 05:16 AM
Hi Laura,

Here is a help article which explains how to primary key value for parent item in hierarchy on Update/Insert. Go through it and see if it is helpful.
Extracting primary key value for parent item in hierarchy on Update/Insert

Shinu
0
Laura
Top achievements
Rank 1
answered on 17 Apr 2009, 05:36 AM
Thank you Shinu...

I was reading this before I posted my question, and I don't think it helps me. I am doing the insert using a radwindow, and the link for the command item is set in the itemcreated function, and when the insert link is clicked, it goes to the client. It does not invoke the itemcommand server side before it calls the javascript to pop up the insert window.

I need a way to get the parent id from the client when I am clicking on the itemcommandtemplate link
0
Laura
Top achievements
Rank 1
answered on 17 Apr 2009, 03:58 PM
Ok...if there is no way to get the parent ID sent to a pop up radwindow on insert, I will have to re-think my logic. If I go to a in grid edit form I will have to use lots of grid template columns to achieve what I want. I will also have to have no automatic update/insert/deletes. I am having difficulty figuring out how to use template columns and 3 level hierarchy to access the textboxes in the templates that will be used for an update/insert. And then using them to send to the insertcommand....Can someone point me in the right direction?

Thanks,
Laura
0
Tsvetoslav
Telerik team
answered on 22 Apr 2009, 09:35 AM
Hello Laura,

You should use the ItemCreated event and the ParentItem property of the details table view as Shinu has indicated in his post. If I have correctly understood your logic, your code for the ItemCreated event should look like the following:

        if (e.Item is GridCommandItem && e.Item.OwnerTableView.Name == "Orders")  
        {  
            LinkButton insertButton = e.Item.FindControl("InitInsertButton"as LinkButton;  
            Button addNewRecordsButton = e.Item.FindControl("AddNewRecordButton"as Button;  
            insertButton.Attributes["OnClick"] = String.Format("ShowInsertServiceForm('{0}')", e.Item.OwnerTableView.ParentItem.GetDataKeyValue("provider_id").ToString());  
            addNewRecordsButton.Attributes["OnClick"] = String.Format("ShowInsertServiceForm('{0}')", e.Item.OwnerTableView.ParentItem.GetDataKeyValue("provider_id").ToString());  
        } 

Then you need to modify your client function to accept a single parameter - the provider ID.

The parent item data keys will be available in the ItemCreated event so you do not need to wait until the ItemCommand event is thrown.


I hope this information helps.


Best Regards,
Tsvetoslav
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
Grid
Asked by
Laura
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Laura
Top achievements
Rank 1
Tsvetoslav
Telerik team
Share this question
or