Accessing key data in the hierarchy demo

3 posts, 0 answers
  1. Dave Hayward
    Dave Hayward avatar
    40 posts
    Member since:
    Jul 2012

    Posted 03 Jan 2010 Link to this post

    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. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 04 Jan 2010 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Dave Hayward
    Dave Hayward avatar
    40 posts
    Member since:
    Jul 2012

    Posted 04 Jan 2010 Link to this post

    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! 
Back to Top