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

Get DataKey from RadGrid

2 Answers 1732 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mike
Top achievements
Rank 1
Mike asked on 17 Dec 2013, 09:57 PM
I have a RadGrid that has a Master Table and a child and grandchild

Master
     Child
         Grandchild

I am using the OnItemCommand and I can't seem to access the Datakey's that are listed in the Grandchild.
foreach (GridDataItem item in rg1.MasterTableView.Items)
          {
              long Id1 = (long)rg1.MasterTableView.Items[0].GetDataKeyValue("Id1");
                  if (item.HasChildItems)
                  
                      foreach (GridDataItem citem in item.ChildItem.NestedTableViews[0].Items)
                      {
                          string Id = citem.GetDataKeyValue("Id2").ToString();
                      }
                  }
           }


<MasterTableView DataKeyNames="Id1" Name="Master">
            <DetailTables>
                <telerik:GridTableView DataKeyNames="Id1,Id2" Name="Child">
                    <DetailTables>
                        <telerik:GridTableView DataKeyNames="Id1,Id2,Id3" Name="Grandchild" EditMode="InPlace">
                            <Columns>

Your help is appreciated.

2 Answers, 1 is accepted

Sort by
0
Accepted
Jayesh Goyani
Top achievements
Rank 2
answered on 18 Dec 2013, 04:41 AM
Hello,

Please try with the below code snippet.

foreach (GridDataItem item in rg1.MasterTableView.Items)
        {
            string Id1Master = item.GetDataKeyValue("Id1").ToString();
            //string tableName = item.OwnerTableView.Name; // you can get table name here
            if (item.HasChildItems)
            {
                foreach (GridDataItem citem in item.ChildItem.NestedTableViews[0].Items)
                {
                    string Id1Child = citem.GetDataKeyValue("Id1").ToString();
                    string Id2Child = citem.GetDataKeyValue("Id2").ToString();
                    //string tableName1 = citem.OwnerTableView.Name;
 
                    if (citem.ChildItem)
                    {
                        foreach (GridDataItem gcitem in citem.ChildItem.NestedTableViews[0].Items)
                        {
                            string Id1Grandchild = gcitem.GetDataKeyValue("Id1").ToString();
                            string Id2Grandchild = gcitem.GetDataKeyValue("Id2").ToString();
                            string Id3Grandchild = gcitem.GetDataKeyValue("Id3").ToString();
                            //string tableName2 = gcitem.OwnerTableView.Name;
                        }
                    }
                }
            }
        }



Thanks,
Jayesh Goyani
0
Mike
Top achievements
Rank 1
answered on 18 Dec 2013, 02:11 PM
Thank you Jayesh!  It works like a charm!!!!!!
:)
Tags
Grid
Asked by
Mike
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Mike
Top achievements
Rank 1
Share this question
or