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

dinamic populate DetailTable

1 Answer 80 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Rudy
Top achievements
Rank 1
Rudy asked on 18 Dec 2008, 12:21 PM
hello...
i want to populate dinamically a gridtableview in the detailtables of my radgrid.
the datasource for this gridtableview must come from a List<myobject>


this is radgrid and c#:

// datasource for radgrid

protected void gridBooth_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
        {
List<Business.SE2_CatalogueSubscription> _stands = new List<Business.SE2_CatalogueSubscription>();
_stands = _dataContext.SE2_CatalogueSubscriptions
                .Where(e => e.idExhibition == _exhibitionId)
                .ToList();

            gridBooth.DataSource = _stands ;
            gridBooth.VirtualItemCount = _stands.Count;;    
        }

the source for my detailtable is :
 public List<Business.SE2_CatalogueSubscriptionsMerceologiche> GetMerceologiche(int idSubscription)
        {
            return
                (_dataContext.SE2_CatalogueSubscriptionsMerceologiches
                    .Where(a => a.idSubscription == idSubscription)
                    .OrderBy(b => b.idSubscriptionMerceologico)
                ).ToList();
        }
// i want to Bind the GridTableView with this List<> and the parameter is idSubscription (idSubscription is the GridRelationFields and also DataKeyfor RadGrid)

<telerik:RadGrid ID="gridBooth" runat="server" AllowPaging="True" AllowCustomPaging="True"
                AllowSorting="True" AutoGenerateColumns="False" GridLines="None"  EnableAJAX="true"
                OnNeedDataSource="gridBooth_NeedDataSource"  OnSortCommand="RadGrid1_SortCommand"
                OnPageIndexChanged="gridBooth_PageIndexChanged" Height="500px"
                                onitemcreated="gridBooth_ItemCreated" Skin="Vista">
                <PagerStyle Mode="NextPrevAndNumeric" />
                
                   <MasterTableView CommandItemDisplay="Top" Name="Subscriptions" HierarchyLoadMode="Client">
                   <DetailTables>
                        <telerik:GridTableView DataKeyNames="idSubscriptionMerceologico"   DataMember="Categories"
                        ShowHeader="true"                      
                        AllowPaging="False" Width="70%" runat="server" AllowCustomPaging="False"
                            NoDetailRecordsText="Nessuna categoria selezionata." NoMasterRecordsText="">
                                <ParentTableRelation>
                                    <telerik:GridRelationFields DetailKeyField="idSubscription" MasterKeyField="idSubscription" />
                                </ParentTableRelation>                                  
                                <Columns>
                                    <telerik:GridBoundColumn SortExpression="idSubscriptionMerceologico" HeaderText="ID" DataField="idSubscriptionMerceologico" UniqueName="idSubscriptionMerceologico">
                                    </telerik:GridBoundColumn>
                                
                                    <telerik:GridBoundColumn SortExpression="merceologico" HeaderText="merceologico" DataField="merceologico" UniqueName="merceologico">
                                    </telerik:GridBoundColumn>
                                </Columns>                                
                            </telerik:GridTableView>                    
                    </DetailTables>  
                   
                   
                   <CommandItemTemplate>
                        <table width="100%" cellpadding=2 cellspacing=2 border=0>
                       <tr>
                           <td class="normal" width="25%" align=left><asp:LinkButton ID="btnExportXLS" runat=server CausesValidation=false OnClick="btnExportXLS_Click"><img src="/images/xls.jpg" border=0 />&nbsp;Totale</asp:LinkButton></td>                           
                           <td class="normal" width="25%" align=left><asp:LinkButton ID="btnExportCSV" runat=server CausesValidation=false OnClick="btnExportCSV_Click">CSV Totale</asp:LinkButton></td>
                           <td class="normal" width="50%" align=center>&nbsp;</td>                       
                       </tr>
                       </table>
                    </CommandItemTemplate>

                    <RowIndicatorColumn>
                        <HeaderStyle Width="20px"></HeaderStyle>
                    </RowIndicatorColumn>
                    <ExpandCollapseColumn>
                        <HeaderStyle Width="20px"></HeaderStyle>
                    </ExpandCollapseColumn>
                    
                                   
                    
                    <Columns>                                            
                        <telerik:GridTemplateColumn DataField="idSubscription" HeaderText="ID" UniqueName="idSubscription" SortExpression="idSubscription">
                        <ItemTemplate>
                            <%# GetIDLink(DataBinder.Eval(Container.DataItem, "idSubscription"), "y")%>
                        </ItemTemplate>
                        </telerik:GridTemplateColumn>
                        <telerik:GridTemplateColumn DataField="idSubscription" HeaderText="ID" visible=false UniqueName="idSubscriptionData" SortExpression="idSubscription">
                        <ItemTemplate>
                            <%# GetIDLink(DataBinder.Eval(Container.DataItem, "idSubscription"), "n")%>
                        </ItemTemplate>
                        </telerik:GridTemplateColumn>
                                        
                        <telerik:GridTemplateColumn DataField="UserId" HeaderText="Espositore"  UniqueName="EspositoreData" SortExpression="UserId">
                        <ItemTemplate>
                            <%# GetEspositore(DataBinder.Eval(Container.DataItem, "UserId"), "n")%>
                        </ItemTemplate>
                        </telerik:GridTemplateColumn>
                   
                        <telerik:GridBoundColumn AllowFiltering="False" DataField="CompanyName" EmptyDataText=""
                            HeaderText="Azienda" UniqueName="CompanyName">
                        </telerik:GridBoundColumn>
                        
                        <telerik:GridBoundColumn AllowFiltering="False" DataField="Address" EmptyDataText=""
                            HeaderText="Indirizzo" UniqueName="Address">
                        </telerik:GridBoundColumn>
 </Columns>
                     
                    
                     
                </MasterTableView>
                <ClientSettings AllowColumnsReorder="True">
                    <Scrolling AllowScroll="True" UseStaticHeaders="True" />
                </ClientSettings>
                <FilterMenu EnableTheming="True">
                    <CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation>
                </FilterMenu>
                <sortingsettings sorttooltip="Clicca per ordinare" />
            </telerik:RadGrid>

1 Answer, 1 is accepted

Sort by
0
Rudy
Top achievements
Rank 1
answered on 19 Dec 2008, 08:40 AM
I got it!!
        protected void gridBooth_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
        {
            if (!e.IsFromDetailTable)
            {
                gridBooth.DataSource = _catlist.Items;
                gridBooth.VirtualItemCount = _catlist.Count;                
            }            
        }

        protected void gridBooth_DetailTableDataBind(object source, GridDetailTableDataBindEventArgs e)
        {
            GridDataItem dataItem = e.DetailTableView.ParentItem;
            int IDSUB = (int)dataItem.GetDataKeyValue("idSubscription");

            switch (e.DetailTableView.Name)
            {
                case "Merce":
                    {
                        e.DetailTableView.DataSource = _catlist.GetMerceologiche(IDSUB);   
                        // this is a call to LINQ that returns a List<Categories>
                        break;
                    }

                case "Case":
                    {
                        e.DetailTableView.DataSource = _catlist.GetCase(IDSUB);      
                        // this is a call to LINQ that returns a List<Details>
                        break;
                    }
            }
            
        }


<telerik:RadGrid ID="gridBooth" runat="server" AllowPaging="True" AllowCustomPaging="True"
                AllowSorting="True" AutoGenerateColumns="False" GridLines="None"  EnableAJAX="true"
                OnNeedDataSource="gridBooth_NeedDataSource"  
                OnDetailTableDataBind="gridBooth_DetailTableDataBind"
                OnSortCommand="RadGrid1_SortCommand"
                OnPageIndexChanged="gridBooth_PageIndexChanged" Height="500px"
                onitemcreated="gridBooth_ItemCreated" Skin="Vista">
                <PagerStyle Mode="NextPrevAndNumeric" />
                
                   <MasterTableView CommandItemDisplay="Top" Name="Subscriptions" DataKeyNames="idSubscription">
....
....
<DetailTables>
                        <telerik:GridTableView Name="Merce" DataKeyNames="idSubscriptionMerceologico"   DataMember="Categories"
                            AllowPaging="False" Width="70%" runat="server" AllowCustomPaging="False" Caption="Dettaglio Categorie Merceologiche Selezionate"
                            NoDetailRecordsText="Nessuna categoria selezionata."
                            NoMasterRecordsText="" AllowSorting="False">                                                            
                            <RowIndicatorColumn>
                            <HeaderStyle Width="20px"></HeaderStyle>
                            </RowIndicatorColumn>

                            <ExpandCollapseColumn>
                            <HeaderStyle Width="20px"></HeaderStyle>
                            </ExpandCollapseColumn>
                                <Columns>
                                                        
                                    <telerik:GridBoundColumn SortExpression="merceologico" HeaderText="Categorie Merceologiche" DataField="merceologico" UniqueName="merceologico">
                                    </telerik:GridBoundColumn>
                                </Columns>                                
                            </telerik:GridTableView>
                            
                            <telerik:GridTableView Name="Case" DataKeyNames="idCasaRappresentata" DataMember="CaseRapp"
                            AllowPaging="False" Width="70%" runat="server" AllowCustomPaging="False"
                            NoDetailRecordsText="Nessuna casa rappresentata." Caption="Dettaglio Case Rappresentate"
                            NoMasterRecordsText="" AllowSorting="False">                                                            
                            <RowIndicatorColumn>
                            <HeaderStyle Width="20px"></HeaderStyle>
                            </RowIndicatorColumn>

                            <ExpandCollapseColumn>
                            <HeaderStyle Width="20px"></HeaderStyle>
                            </ExpandCollapseColumn>
                                <Columns>                                    
                                    <telerik:GridBoundColumn SortExpression="CasaRappresentata" HeaderText="Case Rappresentate" DataField="CasaRappresentata" UniqueName="CasaRappresentata">
                                    </telerik:GridBoundColumn>
                                    
                                    <telerik:GridBoundColumn SortExpression="Nazione" HeaderText="Nazione" DataField="Nazione" UniqueName="Nazione">
                                    </telerik:GridBoundColumn>
                                </Columns>                                
                            </telerik:GridTableView>                       
                    </DetailTables> 

Tags
Grid
Asked by
Rudy
Top achievements
Rank 1
Answers by
Rudy
Top achievements
Rank 1
Share this question
or