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

Get Parent DataKeyValue

13 Answers 496 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Steven
Top achievements
Rank 1
Steven asked on 27 May 2010, 10:16 AM
Hi,

I have a simple hierarchical grid and I am trying to add a new record with the CommandItemTemplate, a RadWindow and a little javascript but I am having trouble retrieving the DataKeyValue:

The Grid:
        <telerik:RadGrid ID="rgChanges" runat="server" AllowPaging="True" AllowSorting="True" 
            AutoGenerateColumns="False" PageSize="20" Skin="Office2007" GridLines="None"
            <HeaderContextMenu EnableTheming="True"
                <CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation> 
            </HeaderContextMenu> 
            <PagerStyle Mode="NextPrevAndNumeric" Position="TopAndBottom" /> 
            <MasterTableView Width="100%" DataKeyNames="ChangeID" ClientDataKeyNames="ChangeID" 
                AllowMultiColumnSorting="True" Name="ChangesList" CommandItemDisplay="Top"
                <CommandItemTemplate> 
                    <table width="100%" class="rgCommandTable">   
                        <tr>  
                            <td>  
                                <href="#" onclick="return AddNewChange();" ><img src="../images/addnewrecord.gif" alt="" border="0" /> Add new record</a>  
                            </td>  
                            <td align="right">   
                                <asp:LinkButton ID="LinkButton1" runat="server" CommandName="RebindGrid"><img    
                                    src="../images/refresh.gif"    
                                    alt="" border="" /> Refresh</asp:LinkButton>  
                            </td>  
                        </tr>  
                    </table>  
                </CommandItemTemplate> 
                 
                 
                <DetailTables> 
                    <telerik:GridTableView DataKeyNames="ChangeTestID" ClientDataKeyNames="ChangeTestID" Name="Tests" Width="100%" CommandItemDisplay="Top"
                        <CommandItemTemplate> 
                            <table width="100%" class="rgCommandTable">   
                                <tr>  
                                    <td>  
                                        <href="#" onclick="return AddNewTest();" ><img src="../images/addnewrecord.gif" alt="" border="0" /> Add new record</a>  
                                    </td>  
                                    <td align="right">   
                                        <asp:LinkButton ID="LinkButton1" runat="server" CommandName="RebindGrid"><img    
                                            src="../images/refresh.gif"    
                                            alt="" border="" /> Refresh</asp:LinkButton>  
                                    </td>  
                                </tr>  
                            </table>  
                        </CommandItemTemplate> 
                        <RowIndicatorColumn> 
                            <HeaderStyle Width="20px" /> 
                        </RowIndicatorColumn> 
                        <ExpandCollapseColumn> 
                            <HeaderStyle Width="20px" /> 
                        </ExpandCollapseColumn> 
                        <Columns> 
                            <telerik:GridBoundColumn DataField="ChangeTestID" HeaderText="ChangeTestID:" UniqueName="ChangeTestID" 
                                Visible="false"
                            </telerik:GridBoundColumn> 
                            <telerik:GridDateTimeColumn DataField="DateOfTest" HeaderText="Date of Test:" UniqueName="DateOfTest" 
                                DataFormatString="{0:D}"
                            </telerik:GridDateTimeColumn> 
                            <telerik:GridBoundColumn DataField="TestedBy" HeaderText="Tested by:" UniqueName="TestedBy"
                            </telerik:GridBoundColumn> 
                            <telerik:GridBoundColumn DataField="Comments" HeaderText="Comments" UniqueName="Comments"
                            </telerik:GridBoundColumn> 
                            <telerik:GridCheckBoxColumn DataField="IsSuccessful" HeaderText="Successful Test:" 
                                UniqueName="IsSuccessful"
                            </telerik:GridCheckBoxColumn> 
                        </Columns> 
                    </telerik:GridTableView> 
                </DetailTables> 
                <RowIndicatorColumn> 
                    <HeaderStyle Width="20px"></HeaderStyle> 
                </RowIndicatorColumn> 
                <ExpandCollapseColumn Visible="True"
                    <HeaderStyle Width="20px"></HeaderStyle> 
                </ExpandCollapseColumn> 
                <Columns> 
                    <telerik:GridBoundColumn DataField="ChangeID" HeaderText="ChangeID:" UniqueName="ChangeID" 
                        Visible="false"
                    </telerik:GridBoundColumn> 
                    <telerik:GridBoundColumn DataField="ChangeTitle" HeaderText="Change Title:" UniqueName="ChangeTitle"
                    </telerik:GridBoundColumn> 
                    <telerik:GridDateTimeColumn DataField="DateOfChange" HeaderText="Date of Change:" 
                        UniqueName="DateOfChange" DataFormatString="{0:D}"
                    </telerik:GridDateTimeColumn> 
                    <telerik:GridBoundColumn DataField="Version" HeaderText="Version:" UniqueName="Version"
                    </telerik:GridBoundColumn> 
                    <telerik:GridBoundColumn DataField="Developer" HeaderText="Developer:" UniqueName="Developer"
                    </telerik:GridBoundColumn> 
                    <telerik:GridBoundColumn DataField="Comments" HeaderText="Comments:" UniqueName="Comments"
                    </telerik:GridBoundColumn> 
                </Columns> 
            </MasterTableView> 
            <ClientSettings AllowColumnsReorder="True" ReorderColumnsOnClient="True" AllowDragToGroup="True"
                <Selecting AllowRowSelect="True"></Selecting> 
                <Selecting AllowRowSelect="true" /> 
                <ClientEvents OnRowDblClick="RowDblClick" /> 
            </ClientSettings> 
        </telerik:RadGrid> 

Javascript:

<script type="text/javascript"
 
            function openTestEditWindow(id,changeid) { 
                var win = newWin("editTest.aspx?id=" + id + "&changeid=" + changeid, "Edit Window", 500, 750, true, refreshPage); 
            } 
 
 
            function AddNewTest(sender, eventArgs) { 
                    //Need to get parent ID here 
                    openTestEditWindow('new''ID here'); 
              } 
 
            function newWin(url, title, height, width, modal, onClose) { 
 
                var win = radopen(url); 
                win.set_height(height); 
                win.set_width(width); 
                win.set_title(title); 
                if (modal == true
                    win.set_modal(true); 
                win.center(); 
                if (onClose != undefined) 
                    win.add_close(onClose); 
                return win; 
            } 
        </script> 


Have tried various methods I have found on the forum here but I just can't seem to get this to work.

13 Answers, 1 is accepted

Sort by
0
Pavlina
Telerik team
answered on 27 May 2010, 04:14 PM
Hello Steven,

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

Best wishes,
Pavlina
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Steven
Top achievements
Rank 1
answered on 28 May 2010, 11:22 AM
Hi Pavlina,

Thanks for that but it doesn't work in my case as the ItemCommand doesn't fire as I am not using any of the built in commands, I really need to be able to pull out the ParentID Client side.
0
Pavlina
Telerik team
answered on 31 May 2010, 02:02 PM
Hi Steven,

I suggest that you examine the following online example which demonstrates how to extract the respective field value for a row through the getDataKeyValue() function:
http://demos.telerik.com/aspnet-ajax/grid/examples/client/keys/defaultcs.aspx

Another approach for fetching values from grid cells is to use the GetCellByColumnUniqueName(rowObject, columnName) method.
http://www.telerik.com/help/aspnet-ajax/grid_getcellbycolumnuniquename.html

additionally, you can use the following method:

http://www.telerik.com/help/aspnet-ajax/grid_get_detailtables.html

to access all the detail tables in the grid control.

I hope this information helps.

Sincerely yours,
Pavlina
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Steven
Top achievements
Rank 1
answered on 01 Jun 2010, 09:11 AM
Hi Pavlina,

Thanks for that but they don't really help me.  The problem I have is that I cannot determine the parentID of the CommandItemTemplate for the child grid.  I can get the childs datakeyvalue no problem and I already have working code to update the records that already exist.  I have also completed the code to insert a new record but I have hardcoded the parentID into the JavaScript function as I have been unable to find a way to extract this value so far.
0
Steven
Top achievements
Rank 1
answered on 02 Jun 2010, 09:59 AM
Is what I am asking for not possible?  I have read through I think most of anything that relates to this in the help files but there is so little information on using the CommandItemTemplate on a child grid.  I am sure I am missing some really simple way to just pick out the ParentID of the CommandItemTemplate?
0
Pavlina
Telerik team
answered on 04 Jun 2010, 03:00 PM
Hi Steven,

Go through the following link, which elaborates on this subject and see if it helps:
http%3A%2F%2Fwww%2Etelerik%2Ecom/community/forums/aspnet-ajax/grid/request-how-to-access-the-grid-command-item-using-client-side-api.aspx

Additionally, you can review the help article below:
http://www.telerik.com/help/aspnet-ajax/grdusinggetitemsgetcolumnmethods.html

Sincerely yours,
Pavlina
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Pavlina
Telerik team
answered on 04 Jun 2010, 03:00 PM
Hi Steven,

Go through the following link, which elaborates on this subject and see if it helps:
http%3A%2F%2Fwww%2Etelerik%2Ecom/community/forums/aspnet-ajax/grid/request-how-to-access-the-grid-command-item-using-client-side-api.aspx

Additionally, you can review the help article below:
http://www.telerik.com/help/aspnet-ajax/grdusinggetitemsgetcolumnmethods.html

Sincerely yours,
Pavlina
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Steven
Top achievements
Rank 1
answered on 17 Jun 2010, 04:01 PM
I gave up using the itemCommandTemplate for this in the end, I just couldn't find any way to get the ParentID of the record that contained the child object.  In the end I just added a column to the parent record and used the existing function I had:

                    <telerik:GridTemplateColumn DataField="Normal" HeaderText="" UniqueName="Normal"
                        <ItemTemplate> 
                            <href="#" onclick="return AddNewTest(<%#DataBinder.Eval(Container, "DataItem.ChangeID").ToString %>);"> 
                                Add Test 
                            </a>                                                    
                        </ItemTemplate> 
                    </telerik:GridTemplateColumn> 

0
Celine Koe
Top achievements
Rank 1
answered on 14 Dec 2010, 09:25 AM
Was there a solution to Steven's original issue? I have the same issue, where I would like to access the DataKey of the parent grid when I insert a new record in the child grid via CommandItemTemplate.

In my child grid, GridTableView > CommandItemTemplate (add new link button), I even tried using a custom CommandName and CommandArgument (which contains the DataKey). But having some trouble retrieving the DataKey or even CommandArgument via javascript.
0
Pavlina
Telerik team
answered on 20 Dec 2010, 11:54 AM
Hi Celine,

I recommend that you examine the following help article which shows how to get the primary key field for up-level rows using DataKeyNames/DataKeyValues:
Extracting primary key value for parent item in hierarchy on Update/Insert

Regards,
Pavlina
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
Steven
Top achievements
Rank 1
answered on 20 Dec 2010, 05:17 PM
The provided example doesn't use the CommandItemTemplate which is where the problem arises.
0
Pavlina
Telerik team
answered on 23 Dec 2010, 12:23 PM
Hi Steven,

Please, open a formal support ticket send us a runnable test project and I will demonstrate on it how to implement the necessary changes.

Thanks in advance.

Regards,
Pavlina
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
Dan
Top achievements
Rank 1
answered on 13 May 2013, 11:59 AM
Hello

I can see that this is quite an old thread and wondered if anyone ever found a solution to this?
I also need to get the parent row ID on the client-side when the user clicks the "Add New Record" button (not a child row) on one of the detail grids. It seems really strange that there's no easy way to get at this information.

Thanks
Dan
Tags
Grid
Asked by
Steven
Top achievements
Rank 1
Answers by
Pavlina
Telerik team
Steven
Top achievements
Rank 1
Celine Koe
Top achievements
Rank 1
Dan
Top achievements
Rank 1
Share this question
or