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

RadGrid Hierarchy Loading

2 Answers 91 Views
Grid
This is a migrated thread and some comments may be shown as answers.
digitall
Top achievements
Rank 1
digitall asked on 19 Jul 2009, 11:26 PM
I am trying to bind a RadGrid instance to a collection of objects such as this:

Region
    -Id, Name, etc
    -List<Locations>

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:

<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"
    <MasterTableView AutoGenerateColumns="false" CommandItemDisplay="Top" CommandItemStyle-Height="30px" DataKeyNames="Id" HierarchyLoadMode="Client"
        <DetailTables> 
            <telerik:GridTableView AutoGenerateColumns="false" runat="server" CommandItemDisplay="Top" CommandItemStyle-Height="30px" Name="Locations"
                <CommandItemTemplate> 
                    <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> 
                </CommandItemTemplate> 
                <ParentTableRelation> 
                    <telerik:GridRelationFields MasterKeyField="Id" DetailKeyField="Id" /> 
                </ParentTableRelation> 
                <Columns> 
                    <telerik:GridTemplateColumn ItemStyle-Wrap="false" ItemStyle-Width="45px"
                        <ItemTemplate> 
                            <asp:Button runat="server" ID="cmEdit" Text="Edit" SkinID="SmallButton" /> 
                        </ItemTemplate> 
                    </telerik:GridTemplateColumn>  
                    <telerik:GridBoundColumn DataField="Id" Visible="false" />                            
                    <telerik:GridBoundColumn DataField="City" HeaderText="City" /> 
                    <telerik:GridBoundColumn DataField="StateProv.Name" HeaderText="State/Prov" /> 
                    <telerik:GridBoundColumn DataField="Country.Name" HeaderText="Country" /> 
                    <telerik:GridBoundColumn DataField="PostalCode" HeaderText="PostalCode" /> 
                </Columns> 
            </telerik:GridTableView> 
        </DetailTables> 
        <CommandItemTemplate> 
            <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> 
        </CommandItemTemplate> 
        <Columns> 
            <telerik:GridTemplateColumn ItemStyle-Wrap="false" ItemStyle-Width="45px"
                <ItemTemplate> 
                    <asp:Button runat="server" ID="cmEdit" Text="Edit" CommandArgument='<%#Eval("Id") %>' SkinID="SmallButton" /> 
                </ItemTemplate> 
            </telerik:GridTemplateColumn> 
            <telerik:GridBoundColumn HeaderText="Code" DataField="Code" /> 
            <telerik:GridBoundColumn HeaderText="Name" DataField="Name" /> 
            <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."  
                            ConfirmDialogType="RadWindow" ConfirmTitle="Delete" ButtonType="ImageButton" CommandName="Delete"  ItemStyle-Width="45px"  
                            Text="Delete" UniqueName="DeleteColumn" ItemStyle-HorizontalAlign="Center" ImageUrl="~/_assets/images/delete.gif"
                <ItemStyle HorizontalAlign="Center" /> 
            </telerik:GridButtonColumn>  
        </Columns> 
    </MasterTableView> 
    <ClientSettings EnableRowHoverStyle="true" /> 
</telerik:RadGrid> 


Here is my code-behind:

Private _Regions As List(Of Core.TenderingRegion) = Nothing 
Protected ReadOnly Property Regions() As List(Of Core.TenderingRegion) 
    Get 
        If Me._Regions Is Nothing Then 
            Me._Regions = New Core.TenderingRegionBiz().GetAllRegions() 
        End If 
 
        Return Me._Regions 
    End Get 
End Property 
 
Protected Sub grRegions_NeedDataSource(ByVal sender As ObjectByVal e As GridNeedDataSourceEventArgs) 
 
    If Not e.IsFromDetailTable Then 
        Me.grRegions.DataSource = Me.Regions 
    End If 
 
End Sub 
 
Protected Sub grRegions_DetailTableDataBind(ByVal sender As ObjectByVal e As GridDetailTableDataBindEventArgs) 
 
    If e.DetailTableView.Name = "Locations" Then 
        Dim locs = From r In Me.Regions Where r.Id = Convert.ToInt32(e.DetailTableView.ParentItem.GetDataKeyValue("Id")) Select r.Locations 
        e.DetailTableView.DataSource = locs 
    End If 
 
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 Answers, 1 is accepted

Sort by
0
digitall
Top achievements
Rank 1
answered on 20 Jul 2009, 07:29 PM
Anyone? I used Vlad's explanation when trying to solve this and it didn't help me either.
0
Georgi Krustev
Telerik team
answered on 22 Jul 2009, 11:47 AM
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.


Regards,
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.
Tags
Grid
Asked by
digitall
Top achievements
Rank 1
Answers by
digitall
Top achievements
Rank 1
Georgi Krustev
Telerik team
Share this question
or