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

Hierarchy grid. Get get_detailTables selected row values on client side

8 Answers 663 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mac P
Top achievements
Rank 1
Mac P asked on 22 Jun 2010, 08:34 PM
Hello,

My scenario is that i have a grid with single level nesting. Order is parent grid and orderaddress is the child grid.

I have a link on the parent order called assign. On assign click i get data key of orderid and build the object based on row columns
 var oArg = new Object();
 oArg.OrderId= selectedRow.getDataKeyValue("OrderId");
oArg.name= masterTable.getCellByColumnUniqueName(selectedRow, "Name").innerHTML;
oArg.age= masterTable.getCellByColumnUniqueName(selectedRow, "age").innerHTML;

All works till now.
The problem is i need to associate single address from the details grid. I have row selection for child grid. How do i get primary key and other objects from detail table?

For eg. if i have 3 rows expanded than i need to get the selected child object of the row on which the link is clicked.
Once i get the object i need to build following object
var vAddress  = new Object()
vAddress.AddressId = get addressid primary key from detailsview
vAddress.Address1 =  get address1 as innerhtml from the detailsview


Please help

Regards
Mac




8 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 23 Jun 2010, 09:22 AM
Hello Mac,

In order to achieve this, In ItemCreated event attach "onclick" event to LinkButton and to pass the row index to the client event handler. In the event handler you can access the corresponding DetailTable and DataKeyValue of selected rows in that DetailTable. Sample code is given below.

ASPX:
 <telerik:RadGrid ID="RadGrid1" runat="server" DataSourceID="SqlDataSource3"
    <MasterTableView Name="Master" runat="server" DataKeyNames="OrderID" DataSourceID="SqlDataSource3"
       <Columns> 
          <telerik:GridTemplateColumn> 
             <ItemTemplate> 
                <asp:LinkButton ID="LinkButton1" runat="server">LinkButton</asp:LinkButton> 
             </ItemTemplate> 
          </telerik:GridTemplateColumn> 
        </Columns> 
      <DetailTables> 
        <telerik:GridTableView runat="server" DataKeyNames="EmployeeID" ClientDataKeyNames="EmployeeID" Name="DetailTableView1" DataSourceID="SqlDataSource1"
                   . . . . . . . . . . . . . . . . . . 

C#:
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e) 
    { 
        if (e.Item is GridDataItem && e.Item.OwnerTableView.Name=="Master"
        { 
            GridDataItem item = (GridDataItem)e.Item; 
            LinkButton btn = (LinkButton)item.FindControl("LinkButton1"); 
            btn.Attributes.Add("onclick""ClientClick('" + item.ItemIndex + "');"); 
        } 
    } 

Java Script:
<script type="text/javascript"
    function ClientClick(index) 
       { 
        var grid = $find("<%=RadGrid1.ClientID %>"); 
        var MasterTable = grid.get_masterTableView(); 
        var row = MasterTable.get_dataItems()[index]; 
        var selectedItem = row.get_nestedViews()[0].get_selectedItems()[0]; 
        var detailkeyValue = selectedItem.getDataKeyValue("EmployeeID"); 
        } 
</script> 

Thanks,
Princy.
0
Mac P
Top achievements
Rank 1
answered on 23 Jun 2010, 04:05 PM
Worked great.
Thanks.
0
Murthy
Top achievements
Rank 1
answered on 02 Aug 2010, 07:38 AM
Hi telerik Team,

i am displaying data in n-level hierarchy in radGrid with self hierarchy,

I need to get selected row information. Selected row can be there in any nested table or in master table.

Could any one has a work around for this.

Thanks,
Murthy.

0
Pavlina
Telerik team
answered on 05 Aug 2010, 10:44 AM
Hi Murthy,

I suggest you review the help topic below which elaborates on this subject and see if it helps:
http://www.telerik.com/help/aspnet-ajax/grdextractparentrowcontentonclientselectioninhierarchy.html

All the best,
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
Francis Frank
Top achievements
Rank 1
answered on 01 Nov 2011, 06:27 PM
Please when i put the LinkButton in the child grid, the code behind could not find it

Can someone help me to locate the linkbutton inside the child grid

Thanks Guy
0
Shinu
Top achievements
Rank 2
answered on 02 Nov 2011, 05:06 AM
Hello Francis,

You can access the child grid by specifying the Name property for DetailTable as shown below.

C#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
  if (e.Item is GridDataItem && e.Item.OwnerTableView.Name == "DetailTableView1")//here set the Name of child grid as DetailTableView1
   {
    GridDataItem item = (GridDataItem)e.Item;
   LinkButton link = (LinkButton)item.FindControl("LinkButton1");
   }
}

Thanks,
Shinu.
0
Sharmin
Top achievements
Rank 1
answered on 23 Jul 2013, 04:28 PM
Hi,

I have a 3 level nested radgrid. I would like to get the specific record of the child table expanded when the page is opened.
For e.g, in this example, it is mentioned how the first row of the first child grids can be expanded. But it has not been told that how I can expand the 3rd row. So for the above example, I would like to programmatically find 10507 inside ANTON and then expand it.

Thanks,
Sharmin
0
Sharmin
Top achievements
Rank 1
answered on 24 Jul 2013, 04:29 PM
Never mind. I found it out...
Tags
Grid
Asked by
Mac P
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Mac P
Top achievements
Rank 1
Murthy
Top achievements
Rank 1
Pavlina
Telerik team
Francis Frank
Top achievements
Rank 1
Shinu
Top achievements
Rank 2
Sharmin
Top achievements
Rank 1
Share this question
or