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:
Here is my code-behind:
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.
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 Object, ByVal e As GridNeedDataSourceEventArgs) | |
If Not e.IsFromDetailTable Then | |
Me.grRegions.DataSource = Me.Regions | |
End If | |
End Sub | |
Protected Sub grRegions_DetailTableDataBind(ByVal sender As Object, ByVal 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.