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

Tutorial for editing in nested grid

2 Answers 185 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Dennis Gundersen
Top achievements
Rank 1
Dennis Gundersen asked on 21 Oct 2009, 10:47 PM
Hi

I've got a nested gridview which I want to be editable. The master gridview works fine out of the box, but I need to set one of the controls in the nested grid to the parent key field value at insert, and preferably hide it in edit mode as well. Is there a tutorial for how this is done somewhere?

Grid one: PersonID
Grid two: AddressID, PersonID (must get value from parent grid)....

Re
Dennis

2 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 22 Oct 2009, 08:49 AM
Hello Dennis,

I suppose you are using a Hierarchical grid. If thats the case then, here's an example to achieve a similar scenario as yours. You can alter the logic according to your requirement.
aspx:
<telerik:RadGrid ID="RadGrid1" runat="server" DataSourceID="SqlDataSource1" OnItemDataBound="RadGrid1_ItemDataBound" OnItemCommand="RadGrid1_ItemCommand">           
       <MasterTableView CommandItemDisplay="Top" Name="Master">                    
              <DetailTables>                     
                     <telerik:GridTableView CommandItemDisplay="Top" EditMode="InPlace" DataSourceID="SqlDataSource2" Name="Detail" runat="server">                        
                       

c#:
protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e) 
    { 
 
        if ((e.Item is GridDataInsertItem) && (e.Item.OwnerTableView.IsItemInserted)) 
        { 
            GridDataInsertItem insertItem = (GridDataInsertItem)e.Item; 
            ((TextBox)insertItem["BoundColumnUniqueName"].Controls[0]).Text = insertItem.OwnerTableView.ParentItem.GetDataKeyValue("FirstName").ToString(); 
 
        }  
   } 
 
protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e) 
    { 
        if (e.Item.OwnerTableView.Name == "Detail"// to check for the detail table 
        { 
            GridBoundColumn col = (GridBoundColumn)e.Item.OwnerTableView.GetColumn("BoundColumnUniqueName");            
            if (e.CommandName == RadGrid.EditCommandName) 
            { 
                col.ReadOnly = true
            } 
            else 
            { 
                col.ReadOnly = false
            }             
         } 
    } 

Hope this helps..
Princy.
0
Dennis Gundersen
Top achievements
Rank 1
answered on 22 Oct 2009, 11:23 PM
Excellent, thank you.

Re
Dennis
Tags
Grid
Asked by
Dennis Gundersen
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Dennis Gundersen
Top achievements
Rank 1
Share this question
or