Hello
Please can someone have a look at what i have done wrong below. if i uncomment the line 'e.DetailTableView.DataBind()' it seems to go into an infinate loop and times out...if i remove that line i just get No child records to display. i have got 6 records in objMonitor that have loaded ok.
thanks so much as just cant seem to get it working.
Private Sub radgridstats_DetailTableDataBind(ByVal source As Object, ByVal e As Telerik.Web.UI.GridDetailTableDataBindEventArgs) Handles radgridstats.DetailTableDataBind
Dim dataItem As Telerik.Web.UI.GridDataItem = CType(e.DetailTableView.ParentItem, Telerik.Web.UI.GridDataItem)
Select Case e.DetailTableView.Name
Case "DivisionOne"
Dim DemographicID As String = dataItem.GetDataKeyValue("DemographicID").ToString()
Dim objMonitors As New Pearson.Monitors
objMonitors.LoadStats(DemographicID, 1)
e.DetailTableView.DataSource = objMonitors
'e.DetailTableView.DataBind()
End Select
End Sub
3 Answers, 1 is accepted
Hierarchical grid structure is not supported with simple data-binding (calling DataBind()). You may refer the following online demo for getting more details about binding hierarchical Grid dynamically.
Programmatic Binding
Thanks
Shinu.
should i not have anything but the
radgridstats_PreRender
in the code behind...as i was populating the first level rad grid with data usingDim
objMonitors As New Test.Monitors
objMonitors.LoadStats(0, 1)
radgridstats.DataSource = objMonitors
radgridstats.DataBind()
which worked it was just pulling the 2nd heirachy details i was having problems with, I have just tried to do it exactly as the example just now but am not getting anything loaded in my grid but also no errors and i cant find an easy way to debug when no code behind?
Sorry if i am not that clear but i am still learning and really appreciate your help. Hope you dont mind i was pasted what i have now below.
thank you
<telerik:RadGrid ID="radgridstats" OnPreRender="radgridstats_PreRender" ShowStatusBar="true"
runat="server" AutoGenerateColumns="False" AllowSorting="True" AllowMultiRowSelection="False"
AllowPaging="false" GridLines="None">
<MasterTableView HierarchyLoadMode="Client" DataKeyNames="DemographicID" DataSourceID="SqlDataSource1" AllowMultiColumnSorting="True">
<DetailTables>
<telerik:GridTableView Name="DivisionOne" DataSourceID="SqlDataSource2" DataKeyNames="DemographicID" Width="100%" runat="server">
<ParentTableRelation>
<telerik:GridRelationFields DetailKeyField="DemographicID" MasterKeyField="DemographicID" />
</ParentTableRelation>
<DetailTables>
<telerik:GridTableView Name="DivisionTwo" DataSourceID="SqlDataSource3" DataKeyNames="DemographicID" Width="100%" runat="server">
<ParentTableRelation>
<telerik:GridRelationFields DetailKeyField="DemographicID" MasterKeyField="DemographicID" />
</ParentTableRelation>
<Columns>
<telerik:GridBoundColumn SortExpression="CustomerID" HeaderText="Demographic" HeaderButtonType="TextButton"
DataField="DemographicDesc" UniqueName="Demographic">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn SortExpression="ContactName" HeaderText="Talent Reviews Complete" HeaderButtonType="TextButton"
DataField="TRComplete" UniqueName="ContactName">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn SortExpression="CompanyName" HeaderText="Biographies Complete" HeaderButtonType="TextButton"
DataField="BIOComplete" UniqueName="CompanyName">
</telerik:GridBoundColumn>
</Columns>
</telerik:GridTableView>
</DetailTables>
<Columns>
<telerik:GridBoundColumn SortExpression="CustomerID" HeaderText="Division One" HeaderButtonType="TextButton"
DataField="DemographicDesc" UniqueName="Demographic">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn SortExpression="ContactName" HeaderText="Talent Reviews Complete" HeaderButtonType="TextButton"
DataField="TRComplete" UniqueName="ContactName">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn SortExpression="CompanyName" HeaderText="Biographies Complete" HeaderButtonType="TextButton"
DataField="BIOComplete" UniqueName="CompanyName">
</telerik:GridBoundColumn>
</Columns>
</telerik:GridTableView>
</DetailTables>
<Columns>
<telerik:GridTemplateColumn>
<HeaderTemplate>
<asp:Literal ID="litBIO" runat="server" Text="Demographic" />
</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="Label1" Text='<%#Eval("DemographicDesc")%>' runat="server"></asp:Label>
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn>
<HeaderTemplate>
<asp:Label ID="litTR" runat="server" Text="Talent Reviews Complete" />
</HeaderTemplate>
<ItemTemplate>
<table border=0 width=200>
<tr bgcolor='<%#Eval("TRStatsColour")%>'><td><asp:Label Font-Bold ID="lblTRComplete" Text='<%#Eval("TRComplete")%>' runat="server"></asp:Label>%</td></tr>
</table>
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn>
<HeaderTemplate>
<asp:Label ID="litBIO" runat="server" Text="Biographies Complete" />
</HeaderTemplate>
<ItemTemplate>
<table border=0 width=200>
<tr bgcolor='<%#Eval("BIOStatsColour")%>'><td><asp:Label Font-Bold ID="lblBIOComplete" Text='<%#Eval("BIOComplete")%>' runat="server"></asp:Label>%</td></tr>
</table>
</ItemTemplate>
</telerik:GridTemplateColumn>
</Columns>
</MasterTableView>
</telerik:RadGrid>
<asp:SqlDataSource ID="SqlDataSource1" ConnectionString="****"
ProviderName="System.Data.SqlClient" SelectCommand="SELECT * FROM Demographics where " runat="server"></asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSource2" ConnectionString="****"
ProviderName="System.Data.SqlClient" SelectCommand="SELECT * from Demographics
Where ParentDemographicID = @DemographicID "
runat="server">
<SelectParameters>
<asp:SessionParameter Name="DemographicID" SessionField="DemographicID" Type="string" />
</SelectParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSource3" ConnectionString="s****"
ProviderName="System.Data.SqlClient" SelectCommand="SELECT * from Demographics
Where ParentDemographicID = @DemographicID
"
runat="server">
<SelectParameters>
<asp:SessionParameter Name="DemographicID" SessionField="DemographicID" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
I suggest you review the information under the Description section of the online demo linked by Shinu as well as this available in the relevant online help article here. These sources contain all details you need to build your grid hierarchy programmatically with DetailTableDataBind event handling and filter the detail tables sources based on the relations in your DAL or stored procedures.
Best regards,
Sebastian
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.