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

No Records within Detail Grid

4 Answers 28 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Kurt Kluth
Top achievements
Rank 1
Kurt Kluth asked on 26 Aug 2014, 06:14 PM
Have a page that displays some notes from our database and as it will display properly for a certain type of notes.  However it doesn't display for our Board Report notes where the databinding is done a bit differently.  Wondering if you could spot our problem and help us with solving this mystery.  It will load the Master level records but list "No child records to display".

The DetailView.jpg will show how the Board Report notes are to be displayed but NoRecordChildView.jpg is what it comes out to be.  How do we bind the detail grid? 

<telerik:radgrid id="_grdNotes" runat="server" cellspacing="-1" datasourceid="SqlDataSource1"  showheader="False" gridlines="None" style="margin-bottom: 0px;">
            <MasterTableView DataSourceID="SqlDataSource1" HierarchyLoadMode="Client" AutoGenerateColumns="False" DataKeyNames="SubNoteID" Name="Parent" GridLines="None">
                 <DetailTables >
                    <telerik:GridTableView HierarchyLoadMode="Client"  DataKeyNames="SubNoteID" DataSourceID="_srcSubNotes" Width="100%" runat="server" EnableHeaderContextMenu="false" Name="Child" AutoGenerateColumns="False" GridLines="None">
                        <ParentTableRelation>
                            <telerik:GridRelationFields DetailKeyField="SubNoteID" MasterKeyField="SubNoteID">
                            </telerik:GridRelationFields>
                        </ParentTableRelation>
                        <Columns>
                            <telerik:GridTemplateColumn DataField="Comments" FilterControlAltText="Filter Comments column" HeaderText="Comments" SortExpression="Comments" UniqueName="Comments">
                                <ItemTemplate>
                                    <b>(<asp:Label ID="CreatedOnLabel" runat="server" Text='<%#  Eval("FormatedCreatedOn")  %>' ></asp:Label> - <asp:Label ID="FullNameLabel" runat="server" Text='<%# Eval("FullName") %>'></asp:Label>) </b>
                                    <asp:Label ID="CommentsLabel" runat="server" Text='<%# Eval("Comments") %>'></asp:Label>
                                </ItemTemplate>
                            </telerik:GridTemplateColumn>
                            <telerik:GridTemplateColumn UniqueName="UploadedFiles" FilterControlAltText="Filter UploadedFiles column" >
                                <ItemTemplate>
                                    <asp:HiddenField ID="_hdnNoteID" runat="server" Value='<%# DataBinder.Eval(Container.DataItem, "NoteID")%>' />
                                    <ul>
                                        <asp:Repeater ID="_rptNoteFiles" runat="server">
                                            <ItemTemplate>
                                                <li><asp:HyperLink runat="server" ID="_hlNoteFile" NavigateUrl='<%# "~/NoteFiles/" & DataBinder.Eval(Container.DataItem, "FileLoc")%>' Text='<%# DataBinder.Eval(Container.DataItem,"FileDesc") %>'></asp:HyperLink></li>
                                            </ItemTemplate>
                                        </asp:Repeater>
                                    </ul>
                                </ItemTemplate>
                            </telerik:GridTemplateColumn>
                        </Columns>
                    </telerik:GridTableView>
                </DetailTables>
                <Columns>
                    <telerik:GridTemplateColumn DataField="CorrectFollowUpDate" FilterControlAltText="Filter CorrectFollowUpDate column" HeaderText="CorrectFollowUpDate" SortExpression="CorrectFollowUpDate" UniqueName="CorrectFollowUpDate">
                        <ItemTemplate>
                            <b>Follow-up Date: </b>
                            <asp:Label ID="CorrectFollowUpDateLabel" runat="server" Text='<%# Eval("CorrectFollowUpDate") %>'></asp:Label>
                        </ItemTemplate>
                    </telerik:GridTemplateColumn>
                    <telerik:GridTemplateColumn FilterControlAltText="Filter Status column" HeaderText="Status" SortExpression="Status" UniqueName="Status">
                        <ItemTemplate>
                            <asp:HiddenField ID="_hdnCompleted" Value='<%# Eval("Completed") %>' runat="server" />
                            <asp:HiddenField ID="_hdnIncomplete" Value='<%# Eval("Incomplete") %>' runat="server" />
                            <b>Status: <asp:Label ID="StatusLabel" runat="server"></asp:Label></b>
                        </ItemTemplate>
                    </telerik:GridTemplateColumn>
                    <telerik:GridTemplateColumn FilterControlAltText="Filter Add column" UniqueName="AddComplete" HeaderText="" SortExpression="AddComplete">
                        <ItemTemplate>
                            <asp:HiddenField ID="_hdnNoteIDAdd" runat="server" Value='<%# DataBinder.Eval(Container.DataItem, "NoteID")%>' />
                            <a onclick='<%# "AddCompleteNote(" & Eval("NoteID") & ");"%>' href="javascript:void(0);">Add/Complete Note</a>
                        </ItemTemplate>
                    </telerik:GridTemplateColumn>
                </Columns>
            </MasterTableView>
        </telerik:radgrid>
    </div>
</div>
 
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString='<%$ ConnectionStrings:FMS_Conn %>' SelectCommand="sp_getFMSNotes" SelectCommandType="StoredProcedure">
    <SelectParameters>
        <asp:SessionParameter SessionField="charter_num" Name="charter_num" Type="Int32"></asp:SessionParameter>
        <asp:QueryStringParameter QueryStringField="Section" Name="Section" Type="String"></asp:QueryStringParameter>
    </SelectParameters>
</asp:SqlDataSource>
 <asp:SqlDataSource ID="_srcNoteFiles" runat="server"  ConnectionString='<%$ ConnectionStrings:FMS_Conn %>' SelectCommand="sp_getFMSNoteFiles" SelectCommandType="StoredProcedure">
    <SelectParameters>
            <asp:Parameter Name="NoteID" Type="Int32" ></asp:Parameter>
    </SelectParameters>
</asp:SqlDataSource>
 <asp:SqlDataSource ID="_srcSubNotes" runat="server"  ConnectionString='<%$ ConnectionStrings:FMS_Conn %>' SelectCommand="sp_getFMSSubNotes" SelectCommandType="StoredProcedure">
    <SelectParameters>
           <asp:ControlParameter ControlID="_grdNotes" Name="SubNoteID" PropertyName="DataMember" Type="Int32" />
    </SelectParameters>
</asp:SqlDataSource>


Private Sub Page_PreRender(sender As Object, e As EventArgs) Handles Me.PreRender
     _dateFollowUpAdd.MinDate = DateTime.Today.Date.AddDays(1)
 
     If Request("Section") = "FMS-Board" And clscommon.RecursiveFindControl(Page, "_hdnBoardRptID") IsNot Nothing Then
         oConn.Open()
         Dim ocmd As New SqlCommand("sp_seBoardRptFMSNotes", oConn)
         ocmd.CommandType = CommandType.StoredProcedure
         With ocmd.Parameters
             Dim hdnBoardRptID As HiddenField = CType((clscommon.RecursiveFindControl(Page, "_hdnBoardRptID")), HiddenField)
             .Add(New SqlParameter("@BoardRptID", hdnBoardRptID.Value))
         End With
         _grdNotes.DataSourceID = Nothing
         _grdNotes.DataSource = ocmd.ExecuteReader
         _grdNotes.DataBind()
         '_srcSubNotes.DataBind()
         '_grdNotes.MasterTableView.DetailTables(0).DataSourceID = "_srcSubNotes"
         '_grdNotes.MasterTableView.DetailTables(0).Rebind()
         oConn.Close()
     End If
 End Sub




















4 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 1
answered on 27 Aug 2014, 05:59 AM
Hi Kurt Kluth,

The detail tables are coming empty because the data is not bind properly. In the ParentTableRelation, you have set SubNoteID as the KeyField, make sure you set the value according to that. Can you correct your DataSource code as below and check if it helps.

ASPX:
<asp:SqlDataSource ID="_srcSubNotes" runat="server"  ConnectionString='<%$ ConnectionStrings:FMS_Conn %>' SelectCommand="sp_getFMSSubNotes" SelectCommandType="StoredProcedure">
    <SelectParameters>         
     <asp:SessionParameter Name="SubNoteID" SessionField="SubNoteID">
     </asp:SessionParameter>
    </SelectParameters>
</asp:SqlDataSource>

Thanks,
Princy
0
Ryan
Top achievements
Rank 1
answered on 04 Sep 2014, 03:58 PM
Princy,

This did not help with our problem.

Keep in mind that this does work whenever the data of the main grid is bound declaratively. It only breaks when I change the data source in the code behind(during the Page PreRender event).

The new data source does return the needed columns and I have ran the sub notes query against those columns and it returns results. But it still displays no child records.

I have a feeling this is due to the time at which the data of the parent grid is bound(during Page PreRender) but I am not able to bind it any sooner than that because certain data will not be available until after the page load event.
0
Kostadin
Telerik team
answered on 09 Sep 2014, 07:39 AM
Hi Ryan,

I am afraid binding the grid on PreRender event handler is too late in the page live cycle. I would recommend you to check out the following live example which demonstrates how to bind the grid programmatically.

Regards,
Kostadin
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Ryan
Top achievements
Rank 1
answered on 11 Sep 2014, 01:41 PM
Kostadin,

Thank you for the link. I was able to fix the detail table by using the detail table bind event and programmatically binding it. I was still able to bind the main table within the pre-render event.

Here is the code I used:

Private Sub Page_PreRender(sender As Object, e As EventArgs) Handles Me.PreRender
        _dateFollowUpAdd.MinDate = DateTime.Today.Date.AddDays(1)
 
        If Request("Section") = "FMS-Board" And clscommon.RecursiveFindControl(Page, "_hdnBoardRptID") IsNot Nothing Then
            oConn.Open()
            Dim ocmd As New SqlCommand("sp_seBoardRptFMSNotes", oConn)
            ocmd.CommandType = CommandType.StoredProcedure
            With ocmd.Parameters
                Dim hdnBoardRptID As HiddenField = CType((clscommon.RecursiveFindControl(Page, "_hdnBoardRptID")), HiddenField)
                .Add(New SqlParameter("@BoardRptID", hdnBoardRptID.Value))
            End With
            Dim dt As New DataTable
            dt.Load(ocmd.ExecuteReader)
            oConn.Close()
            _grdNotes.DataSourceID = Nothing
            _grdNotes.DataSource = dt
            _grdNotes.DataBind()
 
 
        End If
    End Sub
 
  Private Sub _grdNotes_DetailTableDataBind(sender As Object, e As GridDetailTableDataBindEventArgs) Handles _grdNotes.DetailTableDataBind
        'e.DetailTableView.DataSourceID = _srcSubNotes
 
        Dim item As GridDataItem = DirectCast(e.DetailTableView.ParentItem, GridDataItem)
        Dim noteID As HiddenField = DirectCast(item("AddComplete").FindControl("_hdnNoteIDAdd"), HiddenField)
        
       oConn.Open()
        
        Dim ocmd2 As New SqlCommand("sp_getFMSSubNotes", oConn)
        ocmd2.CommandType = CommandType.StoredProcedure
        With ocmd2.Parameters
            .Add(New SqlParameter("@SubNoteID", noteID.Value))
        End With
        Dim dt As New DataTable
        dt.Load(ocmd2.ExecuteReader)
        oConn.Close()
        e.DetailTableView.DataSource = Nothing
        e.DetailTableView.DataSource = dt
 
    End Sub



Tags
Grid
Asked by
Kurt Kluth
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 1
Ryan
Top achievements
Rank 1
Kostadin
Telerik team
Share this question
or