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

[Solved] sharing DataKeyNames across hierarchy grid

5 Answers 162 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Gijo
Top achievements
Rank 1
Gijo asked on 18 Nov 2009, 09:43 PM

Hi,

I have got a hierarchy grid with three levels.

At the top most level, 'GenericName' as DataKeyNames.
At the second level,'RegionId' as DataKeyNames.
At the third level,'StateId' as DataKeyNames.

I want to access the DataKeyNames('GenericName') in the top most level at the third level.


Thanks,
Gijo Joseph.

5 Answers, 1 is accepted

Sort by
0
Suresh K
Top achievements
Rank 1
answered on 19 Nov 2009, 06:24 AM
hi.
If you are useing <DetailTables>.
u can try this code...
In VB
 For Each item As GridDataItem In RadGrid1.MasterTableView.Items 
            Dim strclientid As String = item.GetDataKeyValue("GenericName") 
            If item.Expanded = True Then 
                For Each hyitem As GridTableView In item.ChildItem.NestedTableViews 
                    For Each dtlitem As GridDataItem In hyitem.Items 
                        Dim straacountid As String = dtlitem.GetDataKeyValue("RegionId") 
                        If dtlitem.Expanded = True Then 
                            For Each childitem As GridTableView In dtlitem.ChildItem.NestedTableViews 
                                For Each childdtlitem As GridDataItem In childitem.Items 
                                    Dim strpvrid As String = childdtlitem.GetDataKeyValue("StateId") 
                                    If childdtlitem.Expanded Then 
                                        
                                    End If 
                                Next 
                            Next 
                        End If 
                    Next 
                Next 
            End If 
        Next 

In C#
 foreach (GridDataItem item in RadGridAudio.MasterTableView.Items) { 
         string strclientid = item.GetDataKeyValue("GenericName"); 
         if (item.Expanded == true) { 
             foreach (GridTableView hyitem in item.ChildItem.NestedTableViews) { 
                 foreach (GridDataItem dtlitem in hyitem.Items) { 
                     string straacountid = dtlitem.GetDataKeyValue("RegionId"); 
                     if (dtlitem.Expanded == true) { 
                         foreach (GridTableView childitem in dtlitem.ChildItem.NestedTableViews) { 
                             foreach (GridDataItem childdtlitem in childitem.Items) { 
                                 string strpvrid = childdtlitem.GetDataKeyValue("StateId"); 
                                 if (childdtlitem.Expanded) { 
                                 } 
                                 
                             } 
                         } 
                     } 
                 } 
             } 
         } 
     } 

0
Princy
Top achievements
Rank 2
answered on 19 Nov 2009, 06:41 AM
Hello Gijo,

You can try out the following sample code to access the datakeyvalue of the firstlevel row when on the third level:
aspx:
<telerik:RadGrid ID="RadGrid1" DataSourceID="SqlDataSource1" runat="server" OnItemDataBound="RadGrid1_ItemDataBound">                
       <MasterTableView Name="Master" DataKeyNames="GenericName" DataSourceID="SqlDataSource1"
             <DetailTables> 
                   <telerik:GridTableView DataKeyNames="RegionId" Name="Detail"  DataSourceID="SqlDataSource1" runat="server"
                         <DetailTables> 
                              <telerik:GridTableView Name="Detail1" DataKeyNames="StateId" DataSourceID="SqlDataSource1" 
                                    runat="server"
                                 .... 

c#:
 
  
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)   
    {   
        if (e.Item is GridDataItem && e.Item.OwnerTableView.Name == "Detail1")   
        {   
            GridDataItem item = (GridDataItem)e.Item;           
             
            string strtxt = RadGrid1.MasterTableView.DataKeyValues[(e.Item.OwnerTableView.ParentItem.OwnerTableView.ParentItem.ItemIndex)]["GenericName"].ToString();  
           // ....   
            
        }   
   }   

Thanks
Princy.
0
Gijo
Top achievements
Rank 1
answered on 19 Nov 2009, 03:28 PM
Thanks for the reply.

The event in which I want to access the DataKeyNames is
protected void RadGrid1_DetailTableDataBind(object source, Telerik.Web.UI.GridDetailTableDataBindEventArgs e)
{
         string GenericName = dataItem.GetDataKeyValue("GenericName").ToString();
         ------------------
         ------------------
}.
This is where I bind the detail tables based on DataKeyNames as parameters for Stored Procedure..

The grid I am building can have n details tables. I am looking for a way in which i can access the DataKeyNames  in 2nd detail table in 5th detail table, DataKeyNames  in 1st detail table in 3rd and so forth in DetailTableDataBind event.



DataKeyNames


0
Accepted
Princy
Top achievements
Rank 2
answered on 20 Nov 2009, 06:46 AM
Hello Gijo,

You can try out the following code and modify according to your requirement:
c#:
protected void RadGrid1_DetailTableDataBind(object source, GridDetailTableDataBindEventArgs e) 
    { 
        if (e.DetailTableView.Name == "Detail1"
        { 
            string strtxt = e.DetailTableView.ParentItem.OwnerTableView.ParentItem.GetDataKeyValue("GenericName").ToString(); 
           //....  
        } 
    } 
You can differentiate between the various levels in the hierarchy using the name properties for the various tableviews.

Hope that helps..
Princy.
0
Gijo
Top achievements
Rank 1
answered on 20 Nov 2009, 07:30 PM
Thanks Princy. It helped.
Tags
Grid
Asked by
Gijo
Top achievements
Rank 1
Answers by
Suresh K
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Gijo
Top achievements
Rank 1
Share this question
or