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

Grid Inside Another grid in template column

1 Answer 39 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Dhiyanes
Top achievements
Rank 1
Dhiyanes asked on 14 Sep 2011, 08:13 AM
Hi
I need to place 2 colums inside grid that 2 columns(Radshowattendedtraining,RadshowProvidedtraining) are two different grid please see the code below my problem is i am not able to use grid inside template column only outer grid is visible in code behind but in asp.net control  it is possible to bind the data.plaese suggest iam new to telerik

<

 

asp:Panel runat="server" ID="InnerContainer" >

 

 

 

 

<telerik:RadGrid ID="Radshowtraining" AllowMultiRowSelection="false" AllowSorting="false" runat="server" GridLines="None"

 

 

AllowFilteringByColumn="true" AllowPaging="true" AutoGenerateColumns ="false" PageSize="10" >

 

 

<ClientSettings EnableRowHoverStyle="true" ReorderColumnsOnClient="True" >

 

 

<Selecting AllowRowSelect="true" />

 

 

</ClientSettings>

 

 

 

<MasterTableView Width="100%" AllowMultiColumnSorting="false" AutoGenerateColumns="false"

 

 

DataKeyNames="Id" ClientDataKeyNames="Id">

 

 

 

<Columns>

 

 

 

<telerik:GridTemplateColumn UniqueName="TemplateDeleteColumn" HeaderText="Attended"

 

 

AllowFiltering="false" HeaderStyle-HorizontalAlign="Center" HeaderStyle-VerticalAlign="Middle"

 

 

ItemStyle-VerticalAlign="Middle" ItemStyle-HorizontalAlign="Center" ItemStyle-Width="150px">

 

 

<ItemTemplate>

 

 

<telerik:RadGrid ID="Radshowattendedtraining" AllowMultiRowSelection="false" AllowSorting="false" runat="server" GridLines="None"

 

 

AllowFilteringByColumn="true" AllowPaging="true" AutoGenerateColumns ="false" PageSize="10">

 

 

<MasterTableView Width="100%" AllowMultiColumnSorting="false" AutoGenerateColumns="false">

 

 

<Columns>

 

 

<telerik:GridBoundColumn DataField="Id" HeaderText="Id" Visible ="false" />

 

 

<telerik:GridBoundColumn DataField="Training" HeaderText="Training" />

 

 

<telerik:GridBoundColumn DataField="StartDate" HeaderText="Start Date" />

 

 

<telerik:GridBoundColumn DataField="EndDate" HeaderText="End Date" />

 

 

</Columns>

 

 

</MasterTableView>

 

 

</telerik:RadGrid>

 

 

</ItemTemplate>

 

 

</telerik:GridTemplateColumn>

 

 

 

<telerik:GridTemplateColumn UniqueName="TemplateDeleteColumn" HeaderText="Provided"

 

 

AllowFiltering="false" HeaderStyle-HorizontalAlign="Center" HeaderStyle-VerticalAlign="Middle"

 

 

ItemStyle-VerticalAlign="Middle" ItemStyle-HorizontalAlign="Center" ItemStyle-Width="150px">

 

 

<ItemTemplate>

 

 

<telerik:RadGrid ID="RadshowProvidedtraining" AllowMultiRowSelection="false" AllowSorting="false" runat="server" GridLines="None"

 

 

AllowFilteringByColumn="true" AllowPaging="true" AutoGenerateColumns ="false" PageSize="10">

 

 

<MasterTableView Width="100%" AllowMultiColumnSorting="false" AutoGenerateColumns="false">

 

 

<Columns>

 

 

<telerik:GridBoundColumn DataField="Id" HeaderText="Id" Visible ="false" />

 

 

<telerik:GridBoundColumn DataField="Training" HeaderText="Training" />

 

 

<telerik:GridBoundColumn DataField="StartDate" HeaderText="Start Date" />

 

 

<telerik:GridBoundColumn DataField="EndDate" HeaderText="End Date" />

 

 

</Columns>

 

 

</MasterTableView>

 

 

</telerik:RadGrid>

 

 

</ItemTemplate>

 

 

</telerik:GridTemplateColumn>

 

 

</Columns>

 

 

</MasterTableView>

 

 

<GroupingSettings CaseSensitive="false" />

 

 

</telerik:RadGrid>

 

 

</asp:Panel>

 

1 Answer, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 14 Sep 2011, 05:50 PM
Hello,

<telerik:RadGrid ID="RadGrid1" runat="server" OnNeedDataSource="RadGrid1_NeedDataSource"
            AutoGenerateColumns="false" onitemdatabound="RadGrid1_ItemDataBound">
            <MasterTableView DataKeyNames="ID">
                <Columns>
                    <telerik:GridBoundColumn DataField="Name" UniqueName="Name" HeaderText="Name">
                    </telerik:GridBoundColumn>
                    <telerik:GridTemplateColumn>
                        <ItemTemplate>
                            <telerik:RadGrid ID="RadGrid2" runat="server" OnNeedDataSource="RadGrid2_NeedDataSource"
                                AutoGenerateColumns="true">
                            </telerik:RadGrid>
                        </ItemTemplate>
                    </telerik:GridTemplateColumn>
                </Columns>
            </MasterTableView>
        </telerik:RadGrid>
protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
    dynamic data = new[] {
        new { ID = 1, Name ="Name1"},
        new { ID = 2, Name = "Name2"},
        new { ID = 3, Name = "Name3"},
        new { ID = 4, Name = "Name4"},
        new { ID = 5, Name = "Name5"}
    };
 
    RadGrid1.DataSource = data;
}
protected void RadGrid2_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
    RadGrid RadGrid2 = sender as RadGrid;
    string strId = ((GridDataItem)RadGrid2.NamingContainer).GetDataKeyValue("ID").ToString();
    dynamic data = new[] {
        new { ID = 11, Name ="Name11_" + strId},
        new { ID = 22, Name = "Name22_" + strId},
        new { ID = 33, Name = "Name33_"+ strId},
        new { ID = 44, Name = "Name44_"+ strId},
        new { ID = 55, Name = "Name55_" + strId}
    };
 
    RadGrid2.DataSource = data;
}
 
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
    if (e.Item is GridDataItem)
    {
        GridDataItem item = e.Item as GridDataItem;
        RadGrid RadGrid2 = (RadGrid)item.FindControl("RadGrid2");
        RadGrid2.Rebind();
    }
}

let me know if any concern.

Thanks,
Jayesh Goyani
Tags
Grid
Asked by
Dhiyanes
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Share this question
or