RadGrid Hierarchy Loading

3 posts, 0 answers
  1. digitall
    digitall avatar
    169 posts
    Member since:
    Jun 2006

    Posted 19 Jul 2009 Link to this post

    I am trying to bind a RadGrid instance to a collection of objects such as this:

        -Id, Name, etc

    I am using the NeedDataSource event and DetailTableDatabind event to accomplish this, but something isn't working right as I don't get any data back for the child entities. When I run through everything in intellisense I can see the DetailTableView.DataSource property contains the objects I expect, but upon binding nothing shows up for the DetailTable except a single empty row (regardless of whether there are 0 or 100 records present). If I try and add a DataKeyName or parent relationship entry it tells me the property doesn't exist on my object, yet it definitely does. In fact, if I use the <%# Eval("Property") %> tag on any property (like in a template column) it tells me that property doesn't exist.

    Here is my markup:

    1 <telerik:RadGrid runat="server" ID="grRegions" OnNeedDataSource="grRegions_NeedDataSource" OnItemDataBound="grRegions_ItemDataBound" OnItemCommand="grRegions_ItemCommand" Skin="Default2006" Width="750px" AllowPaging="true" PageSize="25" PagerStyle-Mode="NumericPages" OnDetailTableDataBind="grRegions_DetailTableDataBind"
    2     <MasterTableView AutoGenerateColumns="false" CommandItemDisplay="Top" CommandItemStyle-Height="30px" DataKeyNames="Id" HierarchyLoadMode="Client"
    3         <DetailTables> 
    4             <telerik:GridTableView AutoGenerateColumns="false" runat="server" CommandItemDisplay="Top" CommandItemStyle-Height="30px" Name="Locations"
    5                 <CommandItemTemplate> 
    6                     <asp:Image ID="Image2" runat="server" ImageUrl="~/_assets/images/AddRecord.gif" BorderStyle="None" hspace="5" /><a href="javascript:void(0);" onclick="javascript:__associateLocation(<%#Eval("RegionId") %>);">Associate Location</a> 
    7                 </CommandItemTemplate> 
    8                 <ParentTableRelation> 
    9                     <telerik:GridRelationFields MasterKeyField="Id" DetailKeyField="Id" /> 
    10                 </ParentTableRelation> 
    11                 <Columns> 
    12                     <telerik:GridTemplateColumn ItemStyle-Wrap="false" ItemStyle-Width="45px"
    13                         <ItemTemplate> 
    14                             <asp:Button runat="server" ID="cmEdit" Text="Edit" SkinID="SmallButton" /> 
    15                         </ItemTemplate> 
    16                     </telerik:GridTemplateColumn>  
    17                     <telerik:GridBoundColumn DataField="Id" Visible="false" />                            
    18                     <telerik:GridBoundColumn DataField="City" HeaderText="City" /> 
    19                     <telerik:GridBoundColumn DataField="StateProv.Name" HeaderText="State/Prov" /> 
    20                     <telerik:GridBoundColumn DataField="Country.Name" HeaderText="Country" /> 
    21                     <telerik:GridBoundColumn DataField="PostalCode" HeaderText="PostalCode" /> 
    22                 </Columns> 
    23             </telerik:GridTableView> 
    24         </DetailTables> 
    25         <CommandItemTemplate> 
    26             <asp:Image ID="Image2" runat="server" ImageUrl="~/_assets/images/AddRecord.gif" BorderStyle="None" hspace="5" /><a href="javascript:void(0);" onclick="javascript:__showRadWindow(null);">Add Region</a> 
    27         </CommandItemTemplate> 
    28         <Columns> 
    29             <telerik:GridTemplateColumn ItemStyle-Wrap="false" ItemStyle-Width="45px"
    30                 <ItemTemplate> 
    31                     <asp:Button runat="server" ID="cmEdit" Text="Edit" CommandArgument='<%#Eval("Id") %>' SkinID="SmallButton" /> 
    32                 </ItemTemplate> 
    33             </telerik:GridTemplateColumn> 
    34             <telerik:GridBoundColumn HeaderText="Code" DataField="Code" /> 
    35             <telerik:GridBoundColumn HeaderText="Name" DataField="Name" /> 
    36             <telerik:GridButtonColumn ConfirmText="Are you sure you wish to permanently remove this region?<br /><br />This action will remove all associated locations and is not reversible."  
    37                             ConfirmDialogType="RadWindow" ConfirmTitle="Delete" ButtonType="ImageButton" CommandName="Delete"  ItemStyle-Width="45px"  
    38                             Text="Delete" UniqueName="DeleteColumn" ItemStyle-HorizontalAlign="Center" ImageUrl="~/_assets/images/delete.gif"
    39                 <ItemStyle HorizontalAlign="Center" /> 
    40             </telerik:GridButtonColumn>  
    41         </Columns> 
    42     </MasterTableView> 
    43     <ClientSettings EnableRowHoverStyle="true" /> 
    44 </telerik:RadGrid> 

    Here is my code-behind:

    1 Private _Regions As List(Of Core.TenderingRegion) = Nothing 
    2 Protected ReadOnly Property Regions() As List(Of Core.TenderingRegion) 
    3     Get 
    4         If Me._Regions Is Nothing Then 
    5             Me._Regions = New Core.TenderingRegionBiz().GetAllRegions() 
    6         End If 
    8         Return Me._Regions 
    9     End Get 
    10 End Property 
    12 Protected Sub grRegions_NeedDataSource(ByVal sender As ObjectByVal e As GridNeedDataSourceEventArgs) 
    14     If Not e.IsFromDetailTable Then 
    15         Me.grRegions.DataSource = Me.Regions 
    16     End If 
    18 End Sub 
    20 Protected Sub grRegions_DetailTableDataBind(ByVal sender As ObjectByVal e As GridDetailTableDataBindEventArgs) 
    22     If e.DetailTableView.Name = "Locations" Then 
    23         Dim locs = From r In Me.Regions Where r.Id = Convert.ToInt32(e.DetailTableView.ParentItem.GetDataKeyValue("Id")) Select r.Locations 
    24         e.DetailTableView.DataSource = locs 
    25     End If 
    27 End Sub 

    It's definitely driving me crazy as to why the expected entities exist in the DataSource property of the DetailTableView but when it goes to show the records it always shows one line item that is blank.
  2. digitall
    digitall avatar
    169 posts
    Member since:
    Jun 2006

    Posted 20 Jul 2009 Link to this post

    Anyone? I used Vlad's explanation when trying to solve this and it didn't help me either.
  3. Georgi Krustev
    Georgi Krustev avatar
    3725 posts

    Posted 22 Jul 2009 Link to this post

    Hello Scott,

    I have answered to the support thread opened on the same matter. Here is a quote of the answer:

    Hello Scott,

    Thank you for contacting us.

    For your convenience I have attached a simple test project which implements the suggested approach.

    Please examine it and let me know if other questions arise.

    Georgi Krustev
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
Back to Top