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

RadGrid - Self-referencing Hierarchy

2 Answers 187 Views
Grid
This is a migrated thread and some comments may be shown as answers.
SomeName
Top achievements
Rank 1
SomeName asked on 14 Jul 2011, 03:48 PM
I have setup an application according to this demo:
http://demos.telerik.com/aspnet-ajax/grid/examples/hierarchy/selfreferencing/defaultcs.aspx

Now i am facing a problem. 
I dont know how to fetch the DataKey from my mastertableview (parent item).

My Grid looks like:
-Parent A
    -Child A
    -Child B
-Parent B

In the nestedtableview under Parent A (holding Child A and Child B) i hit the new button thats in the command item template, and want to insert Child C. Now i dont know how to get the DataKeyValue from Parent A, so that i can set the correct relation in my code behind insert method.

Hope you guys can help me.

Update:
Some pseudo code for further explanation:
protected void paGrid_Insert(object source, GridCommandEventArgs e)
{
    string parentID = e.Item.ParentItem.DataKeyValues["PARENT_ID"];
    //SQL Insert Statement with the parentID to set Relation ...
}

2 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 15 Jul 2011, 06:08 AM
Hello,

Try the following code snippet in InsertCommand to get DataKeyNames.

C#:
protected void RadGrid2_InsertCommand(object sender, GridCommandEventArgs e)
{
        if (e.Item is GridEditFormInsertItem && e.Item.OwnerTableView.IsItemInserted)
        {
           GridEditFormInsertItem insertItem = (GridEditFormInsertItem)e.Item;                   
           GridDataItem parentItem = e.Item.OwnerTableView.ParentItem;
           string datakey = parentItem.OwnerTableView.DataKeyValues[parentItem.ItemIndex]["PARENT_ID"].ToString();
        }
}

Thanks,
Princy.
0
SomeName
Top achievements
Rank 1
answered on 15 Jul 2011, 06:56 AM
Thanks alot!

Didnt know that i have to get the ParentItem, over the OwnerTableView Property.
Tags
Grid
Asked by
SomeName
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
SomeName
Top achievements
Rank 1
Share this question
or