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

Master Detail without calling DB

3 Answers 69 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Sidharth
Top achievements
Rank 1
Sidharth asked on 10 Nov 2011, 07:03 PM
Hi all,

I have a RadGrid that displays "Files" and a details grid that displays "File Records". I've got this working by setting the GridTableView in the DetailTables to use a DataSource, like so:

<div class="row">
Uploaded between
<telerik:RadDatePicker ID="rdpFrom" runat="server" DateInput-AutoPostBack="true"></telerik:RadDatePicker> and
<telerik:RadDatePicker ID="rdpTo" runat="server" DateInput-AutoPostBack="true"></telerik:RadDatePicker>
</div>
 
<telerik:RadGrid ID="rgMemberUploads" runat="server" DataSourceID="odsMemberUploads" AllowPaging="true" PageSize="10" >
    <MasterTableView AutoGenerateColumns="false" DataSourceID="odsMemberUploads" DataKeyNames="ID">
        <DetailTables>
            <telerik:GridTableView AutoGenerateColumns="false" NoMasterRecordsText="No master record" NoDetailRecordsText="No invalid records" DataSourceID="odsMemberFileRecords" DataKeyNames="ID"  HierarchyLoadMode="ServerOnDemand">
                <ParentTableRelation>
                    <telerik:GridRelationFields DetailKeyField="FileID" MasterKeyField="ID" />
                </ParentTableRelation>
                <Columns>
                    <telerik:GridBoundColumn DataField="RecordIndex" ReadOnly="true" HeaderText="Row"></telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="ErrorMessage" ReadOnly="true" HeaderText="Error Message"></telerik:GridBoundColumn>
                </Columns>
            </telerik:GridTableView>
        </DetailTables>
 
        <Columns>
            <telerik:GridDateTimeColumn DataField="UploadedFile.UploadedDate" ReadOnly="true" HeaderText="Uploaded On"></telerik:GridDateTimeColumn>
            <telerik:GridTemplateColumn HeaderText="Uploaded By">
                <ItemTemplate>
                    <%# Eval("UploadedFile.UploadedByNT")?? Eval("UploadedFile.UploadedByName") %>
                </ItemTemplate>
            </telerik:GridTemplateColumn>
            <telerik:GridBoundColumn DataField="UploadedFile.Filename" ReadOnly="true" HeaderText="File"></telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="UploadedFile.Status" ReadOnly="true" HeaderText="Status"></telerik:GridBoundColumn>
            <telerik:GridTemplateColumn HeaderText="Error Details">
                <ItemTemplate>
                    <span class="errorMessage">
                        <%# Eval("UploadedFile.ErrorMessage") %>
                    </span>
                </ItemTemplate>
            </telerik:GridTemplateColumn>
            <telerik:GridDateTimeColumn DataField="UploadedFile.CompletedDate" ReadOnly="true" HeaderText="Completed On"></telerik:GridDateTimeColumn>
        </Columns>
    </MasterTableView>
</telerik:RadGrid>
 
<asp:ObjectDataSource ID="odsMemberUploads" runat="server"
    OldValuesParameterFormatString="original_{0}" SelectMethod="Search"
    TypeName="File">
    <SelectParameters>
        <asp:ControlParameter ControlID="rdpFrom" Name="uploadedFrom"
            PropertyName="SelectedDate" Type="DateTime" />
        <asp:ControlParameter ControlID="rdpTo" Name="uploadedTo"
            PropertyName="SelectedDate" Type="DateTime" />
    </SelectParameters>
</asp:ObjectDataSource>
 
<asp:ObjectDataSource ID="odsMemberFileRecords" runat="server"
    OldValuesParameterFormatString="original_{0}" SelectMethod="SearchRecords"
    TypeName="File">
    <SelectParameters>
        <asp:Parameter Name="FileID" DbType="Guid" />
    </SelectParameters>
</asp:ObjectDataSource>

The only issue that I have is that main "File" datasource (odsMemberUploads) returns an object that has a property with contains the the records. So ideally I would like the DataSource of the GridTableView to be the RecordsProperty. So I tried doing: 

            <telerik:GridTableView DataSource='<%#Eval("UploadedFile.Records")%>'>

But that didn't work.

I tried to use the NeedDataSource and DetailTableDataBind but the DataItem of the ParentItem is empty.

Is there anyway to do what I would like?

Appreciate your words of wisdom.

Kind regards
Sidharth

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 11 Nov 2011, 06:27 AM
Hello Sidharth,

You can access the DataKeyValue as explained in the demo.
Grid / Programmatic Binding

Thanks,
Princy.
0
Sidharth
Top achievements
Rank 1
answered on 11 Nov 2011, 11:34 AM
Hi Princy,

Thanks for your reply. That article seems to be doing what I'm doing just now, but just from the code-behind. I.e. on every show of the details table it will hit the database again to get the details record. What I would like, if possible, is to not do that. The reason being because my main master table already has a property "Records" that already has all the records loaded. Maybe I should look more at the MasterTableView's Item databound and then manual bind the detailstableview with the Records at that time?

What do you think is that the proper way of doing it with telerik radgrid?

Thanks once again for your help.

Kind regards
Sidharth
0
Daniel
Telerik team
answered on 16 Nov 2011, 02:01 PM
Hello Sidharth,

Please examine the attached demo and let me know if I can assist you further.

Regards,
Daniel
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
Tags
Grid
Asked by
Sidharth
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Sidharth
Top achievements
Rank 1
Daniel
Telerik team
Share this question
or