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

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

1 Answer 108 Views
Grid
This is a migrated thread and some comments may be shown as answers.
ankool
Top achievements
Rank 1
ankool asked on 10 May 2010, 07:40 PM

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

<

 

DetailTables>

 

 

    <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--%>

 

 

        <ParentTableRelation>

 

 

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

 

 

        </ParentTableRelation>

 

 

        <CommandItemTemplate>

 

 

                <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>

 

 

        </CommandItemTemplate>

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.

Thanks
Ankur

 

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 11 May 2010, 08:58 AM
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.
C#:
        
         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.


Javascript:
     
       function AddPayment(index)
       { 
          var grid = $find("<%=RadGrid1.ClientID %>"); 
          var MasterTable = grid.get_masterTableView(); 
          var row = MasterTable.get_dataItems()[index]; 
          alert(row.get_cell("ContactName").innerHTML); 
        } 
Hope this helps.

Regards,
Princy.
Tags
Grid
Asked by
ankool
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or