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

RadGrid inside RadGrid FormTemplate

2 Answers 264 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Borislava
Top achievements
Rank 1
Borislava asked on 10 Sep 2013, 03:51 PM
I have 2 Rad grids.
Parent grid have a FormTemplate.
Inside FormTemplate is a child grid with editMode=inPlace.
On parent Grid_ItemDataBound I binding child grid .
However when I am trying to edit child grid it dissapers .
could you tell me why?

 

2 Answers, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 11 Sep 2013, 05:05 AM
Hello,

Please try with the below code snippet.


<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="false" OnNeedDataSource="RadGrid1_NeedDataSource"
        OnItemDataBound="RadGrid1_ItemDataBound">
        <MasterTableView CommandItemDisplay="Top" DataKeyNames="ID" EditMode="EditForms">
            <Columns>
                <telerik:GridBoundColumn DataField="ID" UniqueName="ID" HeaderText="ID">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="Name" UniqueName="Name" HeaderText="Name">
                </telerik:GridBoundColumn>
                <telerik:GridEditCommandColumn>
                </telerik:GridEditCommandColumn>
            </Columns>
            <EditFormSettings EditFormType="Template">
                <FormTemplate>
                    <telerik:RadGrid ID="RadGrid2" runat="server" AutoGenerateColumns="false" OnNeedDataSource="RadGrid2_NeedDataSource"
                        OnUpdateCommand="RadGrid2_UpdateCommand">
                        <MasterTableView>
                            <Columns>
                                <telerik:GridEditCommandColumn>
                                </telerik:GridEditCommandColumn>
                                <telerik:GridBoundColumn DataField="Name" UniqueName="Name" HeaderText="Name">
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn DataField="ID" UniqueName="ID" HeaderText="ID">
                                </telerik:GridBoundColumn>
                            </Columns>
                        </MasterTableView>
                    </telerik:RadGrid>
                </FormTemplate>
            </EditFormSettings>
        </MasterTableView>
    </telerik:RadGrid>
protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
    {
        dynamic data1 = new[] {
               new { ID = 1, Name ="Name_1",FileName = "jayesh-Softweb.jpg"},
               new { ID = 2, Name = "Name_2",FileName = "jayesh-Softweb.jpg"},
               new { ID = 3, Name = "Name_3",FileName = "jayesh-Softweb.jpg"},
               new { ID = 4, Name = "Name_4",FileName = "jayesh-Softweb.jpg"},
               new { ID = 5, Name = "Name_5",FileName = "jayesh-Softweb.jpg"}
           };
 
        RadGrid1.DataSource = data1;
    }
 
    protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
    {
        if (e.Item.IsInEditMode && e.Item is GridEditFormItem)
        {
            GridEditFormItem item = e.Item as GridEditFormItem;
            RadGrid RadGrid2 = item.FindControl("RadGrid2") as RadGrid;
        }
    }
 
    protected void RadGrid2_UpdateCommand(object sender, GridCommandEventArgs e)
    {
 
    }
 
    protected void RadGrid2_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
    {
        RadGrid RadGrid2 = (sender as RadGrid);
        GridEditableItem item = (RadGrid2.NamingContainer as GridEditFormItem);
        string strKey = item.GetDataKeyValue("ID").ToString();
 
        dynamic data1 = new[] {
               new { ID = 1, Name =DateTime.Now.ToString(),FileName = "jayesh-Softweb.jpg"},
               new { ID = 2, Name = "Name_2",FileName = "jayesh-Softweb.jpg"},
               new { ID = 3, Name = "Name_3",FileName = "jayesh-Softweb.jpg"},
               new { ID = 4, Name = "Name_4",FileName = "jayesh-Softweb.jpg"},
               new { ID = 5, Name = "Name_5",FileName = "jayesh-Softweb.jpg"}
           };
 
        RadGrid2.DataSource = data1;
    }

Let me know if any concern.

Thanks,
Jayesh Goyani
0
Karin
Top achievements
Rank 1
answered on 14 Jan 2016, 10:19 AM

Good morning,

please, how can I make a link between radgrid1 and radgrid 2, I need to link the sqldatasource for radgrid2 by the key of radgrid1

Tags
Grid
Asked by
Borislava
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Karin
Top achievements
Rank 1
Share this question
or