Get the parent table row on clientclick of commanditem button in heirarchical grid

2 posts, 0 answers
  1. ankool
    ankool avatar
    50 posts
    Member since:
    Apr 2007

    Posted 10 May 2010 Link to this post

    I have a heirachical grid and my detail table looks like,






        <rad:GridTableView AutoGenerateColumns="false" runat="server" CommandItemDisplay="Top"



            PageSize="3" Name="Payments" DataKeyNames="PaymentLossDetailID" GridLines="Horizontal"



            AllowFilteringByColumn="false" Width="1200px" NoDetailRecordsText="No payments to display"><%--SIW451--%>






                <rad:GridRelationFields DetailKeyField="PaymentLossDetailID" MasterKeyField="LossDetailID" />









                    <asp:LinkButton ID="lbAddPayment" runat="server" OnClientClick="AddPayment    (this); return false;"><img  style="border:0px" alt="" src="Images/GridAddNew.gif" />Add New Payment</asp:LinkButton><asp:LinkButton ID="lbAddCollection" runat="server" CommandName="InsertCollection"



    Style="padding-left: 30px"><img style="border:0px" alt="" src="Images/GridAddNew.gif" />Add New Collection</asp:LinkButton>




    As you can see right now I am calling AddPayment(this) on command item client click, but what I actually want to pass is the parent row, which was expanded and is the current parent of this detailtable. It could be something like AddPayment(this.OwnerTableView.get_ParentRow())so that I can use the row and then the column values in my client script.

    Please let me know how to achieve this in client script.



  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 11 May 2010 Link to this post

    Hi Ankur,

    You can get the parent item index of the corresponding DetailTable in code behind and attach the client side event for the button placed in CommandItemTemplate by passing the index value. Then in the client event handler, retrieve the index in order to access the parent item.
             protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e) 
                if (e.Item is GridCommandItem && e.Item.OwnerTableView.Name == "Order") 
                    GridCommandItem item = (GridCommandItem)e.Item; 
                    GridDataItem parentItem = (GridDataItem)(item.OwnerTableView.ParentItem); 
                    LinkButton btn = (LinkButton)e.Item.FindControl("lbAddPayment"); 
                    btn.Attributes.Add("onClick", "return AddPayment(" + parentItem.ItemIndex + ");");                   

    Check out the following client script to get the parent row using the index.

           function AddPayment(index)
              var grid = $find("<%=RadGrid1.ClientID %>"); 
              var MasterTable = grid.get_masterTableView(); 
              var row = MasterTable.get_dataItems()[index]; 
    Hope this helps.

  3. DevCraft R3 2016 release webinar banner
Back to Top