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

[Solved] How do I access the header key in this situation?

3 Answers 91 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Boris
Top achievements
Rank 1
Boris asked on 02 May 2013, 04:11 PM
I have a RadGrid with header and details. I have the ParentTableRelation set up.  What I want to do is set up a CommandItemTemplate that contains a link that calls a JavaScript function that in turn does a window.radopen.  So far the Add New Detail link works fine.  

However what I want is something like this:  <a href="#" onclick="return AddDetail(DetailId);">Add New Detail</a>

What is the simplest way to add the DetailId to that call?

<MasterTableView EditMode="PopUp" DataKeyNames="HeaderId" ClientDataKeyNames="HeaderId" Name="Header" CommandItemDisplay="Top" AllowPaging="True">
                    <DetailTables>
                        <telerik:GridTableView runat="server" DataKeyNames="HeaderId,DetailId" ClientDataKeyNames="HeaderId, DetailId" DataMember="Details"  Name="Details" CommandItemDisplay="Top" NoDetailRecordsText="No Detail records to display." HeaderStyle-BackColor="LightCyan"
                            AlternatingItemStyle-BackColor="LightCyan">
                            <CommandItemTemplate>
                               <table style="width: 100%">
                                    <tr>
                                        <td style="width: 160px">
                                            <a href="#" onclick="return AddDetail();">Add New Detail</a>
                                        </td>                                    
                                    </tr>
                                </table>
                            </CommandItemTemplate>

Sorry.  Too fast again.  The solution was to change that to an Asp:Hyperlink and do a call in the ItemCreated event.
if (e.Item is GridCommandItem)
{
      GridCommandItem commandItem = e.Item as GridCommandItem;
      HyperLink editLink = (HyperLink)commandItem.FindControl("AddDetail");
      editLink.Attributes["href"] = "#";
     editLink.Attributes["onclick"] = String.Format("return AddDetail('{0}');", e.Item.OwnerTableView.ParentItem.GetDataKeyValue("DetailId"));
}

3 Answers, 1 is accepted

Sort by
0
Andrey
Telerik team
answered on 07 May 2013, 11:10 AM
Hi,

When you click the button control in the command item the ID of which row should be passed? The way you are trying to access the datakey value won't succeed, because the datakey value is mapped to each record of RadGrid not the structure items like CommandItem or to the whole TableView object.

Regards,
Andrey
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Boris
Top achievements
Rank 1
answered on 07 May 2013, 12:30 PM
?? But it does succeed.   I already have it in production.
0
Andrey
Telerik team
answered on 07 May 2013, 01:19 PM
Hi,

Yes, please excuse me about that.

 I have missed the ParentItem property in your code. Thus the approach that you are using seems correct.

All the best,
Andrey
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Grid
Asked by
Boris
Top achievements
Rank 1
Answers by
Andrey
Telerik team
Boris
Top achievements
Rank 1
Share this question
or