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

[Solved] Insert record using hierarchial grid and user control

1 Answer 113 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Melanie
Top achievements
Rank 1
Melanie asked on 27 Oct 2009, 02:30 PM
Hi,

I have created a master gridview with a child gridview and I would like to insert a new record into the child grid using a user control. 

My only problem is that in this child user control, I need to know which parent record the child record belongs to.  Is there a way from within the user control to determine this?  

Thanks,
Mel
 

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 28 Oct 2009, 07:29 AM
Hello Melanie,

Here's an example of how to access the parent item of a child record while inserting and set the property of the user control with a field value of the parent item:
c#:
protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e) 
    { 
        if (e.Item is GridEditFormInsertItem && e.Item.OwnerTableView.IsItemInserted && e.Item.OwnerTableView.Name == "Detail"
        { 
            GridEditFormInsertItem insertItem = (GridEditFormInsertItem)e.Item;             
            MyUserControl usercntrl = (MyUserControl)insertItem.FindControl(GridEditFormItem.EditFormUserControlID); 
            GridDataItem parentItem = (GridDataItem)insertItem.ParentItem; 
            string strtxt = parentItem["FirstName"].Text; 
            usercntrl.Name = strtxt; 
        } 
    } 

Thanks
Princy.
Tags
Grid
Asked by
Melanie
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or