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

Accessing key data in the hierarchy demo

2 Answers 39 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Dave Hayward
Top achievements
Rank 1
Dave Hayward asked on 03 Jan 2010, 04:52 PM
I'm using a hierarchical grid with a template. My implementation looks quite similar to the demo (http://demos.telerik.com/aspnet-ajax/grid/examples/hierarchy/nestedviewtemplate/defaultcs.aspx). In my case, however, I want the nested grid (ID=OrdersGrid in the demo) to create records.

I'm having a terrible time getting access to the 'EmployeeID' value during the insert operation, which I need to manually initialize the column value. Using the demo as an example, how would I access the EmployeeID value in my initialization code in OrdersGrid_ItemCommand()?

TIA 

2 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 04 Jan 2010, 07:10 AM
Hello Dave,

You can try out the following code to access the datakeyvalue for the parent row of the nested grid. You can preset the value for the required column in the ItemDataBound event of the grid:

c#:
protected void OrdersGrid_ItemDataBound(object sender, GridItemEventArgs e)  
    {        
        if (e.Item is GridEditFormInsertItem && e.Item.OwnerTableView.IsItemInserted) 
        { 
            GridEditFormInsertItem insertitem = (GridEditFormInsertItem)e.Item;  
            GridTableView nestedview = (GridTableView)insertitem.OwnerTableView;  
            GridNestedViewItem nestedviewItem = (GridNestedViewItem)nestedview.NamingContainer.NamingContainer;  
            GridDataItem dataItem = (GridDataItem)nestedviewItem.ParentItem;  
            string Id = dataItem.GetDataKeyValue("ID").ToString();  
            //.... 
             
         }         
    }  

Thanks
Princy.
0
Dave Hayward
Top achievements
Rank 1
answered on 04 Jan 2010, 05:37 PM
Thanks Princy. That was indeed the answer. It still took me a while to figure out how to preset the value for the appropriate column from the ItemdataBound event, but luckily I found an example in the 'Accessing Cells and Rows' section of the demo site.

The Grid control is quite a complex object and the class structures are sometimes difficult to understand. It's probably not a great choise to use as my first Telerik Rad Control, but I'm drivin by my customer's needs, so I must persevere.

Examples and willing experts are essential to successful use.

Thanks again! 
Tags
Grid
Asked by
Dave Hayward
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Dave Hayward
Top achievements
Rank 1
Share this question
or