RadGrid inside RadGrid FormTemplate

3 posts, 0 answers
  1. Borislava
    Borislava avatar
    15 posts
    Member since:
    Oct 2012

    Posted 10 Sep 2013 Link to this post

    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. Jayesh Goyani
    Jayesh Goyani avatar
    2732 posts
    Member since:
    May 2010

    Posted 11 Sep 2013 Link to this post

    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
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. karin
    karin avatar
    19 posts
    Member since:
    Jan 2016

    Posted 14 Jan in reply to Jayesh Goyani Link to this post

    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

Back to Top