RadGrid hiearchy Get ParentID on click of <CommandItemTemplate> Button

2 posts, 0 answers
  1. John
    John avatar
    10 posts
    Member since:
    Aug 2015

    Posted 09 Oct 2018 Link to this post

    I have a radgrid hierarchy structure.  When the user navigates to the third level and clicks on the parent tickmark on the grid, the RadGrid1_ItemCommand is fired and I can retrieve the parent "ProgramID". 

    But I need to pickup the parentID when the user clicks on the command-template button located just on top of the detail rows.  I would like to get the value within a client-side function or server-side if that is easier??? (but cannot get that to work well).  See attachment for a jpg of grid...


    Thank you for you help with this request!


    Client-Side code:

    function openConfirmationWindowNEW(sender, args) {

        var programID= parentItem.OwnerTableView.Items[sender.Item.ItemIndex].GetDataKeyValue("ProgramID");          

        radopen("Storyboard.aspx?carID=programID, "RadWindow2");



    Server-Side Code:

    console.write((string) sender.Item.OwnerTableView.Items[e.Item.ItemIndex].GetDataKeyValue("ProgramID").ToString());


    The code works below but it needs it to work from within a client-side function....

    protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e)

                if (e.Item.OwnerTableView.DataSourceID == "SqlDataSource3")
                    GridDataItem parentItem = (GridDataItem)(e.Item.OwnerTableView.ParentItem);
                    if (parentItem != null)
                        //..tier 2 parent

                        //..tier 3 parent
                        HiddenProgramIDSelected.Value = (string)e.Item.OwnerTableView.Items[e.Item.ItemIndex].GetDataKeyValue("ProgramID").ToString();



  2. Attila Antal
    Attila Antal avatar
    624 posts

    Posted 10 Oct 2018 Link to this post

    Hi John,

    Let's assume the following CommandItemTemplate in any of the DetailTables (any level). The button in it is bound to the ClientClicked event and the handler is commandItemClick 
        <telerik:RadButton ID="RadButton3" runat="server" Text="RadButton" OnClientClicked="commandItemClick" AutoPostBack="false"></telerik:RadButton>

    The commandItemClick event handler
    function commandItemClick(sender, args) {
        var ParentTableView = sender.get_parent()
        var ParentOfParentTableView = ParentTableView.get_parentView();
        // instantiate the dataitems collection. This is required to be able to cast a <tr> element into a dataItem (see next step)
        // Parent Row HTML element
        var parentRowElement = ParentTableView.get_parentRow();
        // cast the HTML row element to DataItem by calling the .control method
        var parentDataItem = ParentTableView.get_parentRow().control;
        var parentRowDataKeyID = parentDataItem.getDataKeyValue("FieldNameOfID"); // NOTE: In order to access a Raw value in the getDataKeyValue() method, this field must be specified in the ClientDataKeyNames collection of the TableView.

        <telerik:GridTableView DataKeyNames="ID" ClientDataKeyNames="ID" Name="ChildGrid" CommandItemDisplay="Top">
            <CommandItemSettings ShowAddNewRecordButton="false" />
                <telerik:RadButton ID="RadButton3" runat="server" Text="RadButton" OnClientClicked="commandItemClick" AutoPostBack="false"></telerik:RadButton>

    Attached you can find an example of a similar scenario.

    Kind regards,
    Attila Antal
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Back to Top