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

NestedViewTemplate Binding to Master

5 Answers 59 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Rick New
Top achievements
Rank 1
Rick New asked on 04 Oct 2010, 12:26 AM
Hi Folks,

I'm trying to follow the example as in http://demos.telerik.com/aspnet-ajax/grid/examples/hierarchy/nestedviewtemplatedeclarativerelations/defaultcs.aspx.

I guess I don't understand the method by which the NestedView gets the Master DataKey ID value.  Clicking on the details arrow always returns the first record.

As in the example, the data is coming from the same table. There are two data sources defined, one for the Master and one for the Nested views.
<asp:LinqDataSource ID="VendorDataSource" EnableObjectTracking="true" EnableUpdate="true" runat="server"
    ContextTypeName="admin.MTSDataClassesDataContext" EntityTypeName=""
    TableName="Vendors">
</asp:LinqDataSource>
<asp:LinqDataSource ID="VendorDetailsDataSource"  EnableUpdate="true" runat="server"
    ContextTypeName="admin.MTSDataClassesDataContext" EntityTypeName=""
    Select="new (ID, Description, Address1, Address2, City, Email2, Phone, FAX, Mobile, Zip, StateID, CountryID, Country, State)"
    Where="ID==@ID"
    TableName="Vendors">
 
    <SelectParameters>
        <asp:Parameter Name="ID" Type="Int32" />
    </SelectParameters>
</asp:LinqDataSource>

The NestedViewSettings are:
<NestedViewSettings DataSourceID="VendorDetailsDataSource">
    <ParentTableRelation>
        <telerik:GridRelationFields  DetailKeyField="ID" MasterKeyField="ID" />
    </ParentTableRelation>
</NestedViewSettings>

and the MasterTable View settings:
<MasterTableView AllowAutomaticUpdates="true" DataKeyNames="ID"  DataSourceID="VendorDataSource">

Again, the issue is that clicking on the details arrow always returns the first item in the database, not the details for the record that was clicked on. 

Thanks for any help.

Rick



5 Answers, 1 is accepted

Sort by
0
Pavlina
Telerik team
answered on 06 Oct 2010, 01:31 PM
Hi Rick,

Try changing your code as shown below and let me know how it goes.
ASPX:
<asp:LinqDataSource ID="VendorDetailsDataSource"  EnableUpdate="true" runat="server"
    ContextTypeName="admin.MTSDataClassesDataContext" EntityTypeName=""
    Select="new (ID, Description, Address1, Address2, City, Email2, Phone, FAX, Mobile, Zip, StateID, CountryID, Country, State)"
    Where="ID==@ID"
    TableName="Vendors">
   
    <WhereParameters>
        <asp:Parameter Name="ID" Type="Int32" />
    </WhereParameters>
</asp:LinqDataSource>

Additionally, I am sending you a simple working project which demonstrates the desired functionality. Please examine it and let me know if other questions or problems arise.

I hope this helps.

Greetings,
Pavlina
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Rick New
Top achievements
Rank 1
answered on 06 Oct 2010, 03:34 PM
Thank you for your reply.

I tried the (==), but it also failed to create the proper binding with the nested view. As a workaround, I removed the DataSourceID from the nested view. This worked, but didn't resolve the issue.

Thanks for the code, I'll utilize it on the next nested view area.

Rick
0
Rick New
Top achievements
Rank 1
answered on 07 Oct 2010, 03:40 AM
Thanks again for your help, still having issues with the next attempt at a nested grid. I'm not using a NestedViewTemplate, if you want me to open a new thread, just let me know.

Trying to display a nested GridTableView of Company Addresses

Clicking on the expand arrow produces no results with the following code

Many to One relationship between Addresses and Companies
FK Addresses.CompanyID   > PK Companies.ID

PK for Addresses is ID

MasterTableView
<MasterTableView DataKeyNames="ID" DataSourceID="CompaniesDataSource">

GridTableView
 <telerik:GridTableView AutoGenerateColumns="true" DataKeyNames="ID,CompanyID"  DataSourceID="AddressesDataSource">
GridRelationFields
 <telerik:GridRelationFields DetailKeyField="CompanyID" MasterKeyField="ID"  />
DataSources
<asp:LinqDataSource ID="CompaniesDataSource" runat="server"  EnableObjectTracking="true"
    ContextTypeName="admin.MTSDataClassesDataContext" EntityTypeName=""
    TableName="Companies" EnableInsert="True" EnableUpdate="True">
</asp:LinqDataSource>
 
<asp:LinqDataSource ID="AddressesDataSource" runat="server"
ContextTypeName="admin.MTSDataClassesDataContext" EntityTypeName=""
TableName="Addresses" EnableInsert="true" EnableUpdate="true" Where="CompanyID==@ID">
    <WhereParameters>
        <asp:Parameter Name="ID" Type="Int32"  />
    </WhereParameters>
</asp:LinqDataSource>
complete relevant .aspx:
    <telerik:RadGrid ID="CompaniesGrid"  runat="server"
        AllowFilteringByColumn="True"  AllowPaging="True" AllowSorting="True"
        AutoGenerateColumns="False" DataSourceID="CompaniesDataSource" GridLines="None">
<MasterTableView DataKeyNames="ID,PrimaryAddressID" DataSourceID="CompaniesDataSource">
<CommandItemSettings ExportToPdfText="Export to Pdf"></CommandItemSettings>
 
<RowIndicatorColumn>
<HeaderStyle Width="20px"></HeaderStyle>
</RowIndicatorColumn>
 
<ExpandCollapseColumn>
<HeaderStyle Width="20px"></HeaderStyle>
</ExpandCollapseColumn>
    <Columns>
        <telerik:GridBoundColumn DataField="Name" HeaderText="Name"
            SortExpression="Name" UniqueName="Name">
        </telerik:GridBoundColumn>
        <telerik:GridTemplateColumn DataField="Address.Country.Country1"  SortExpression='Address.Country.Country1' AllowFiltering="true"  HeaderText="Country">
            <ItemTemplate>
                <asp:Literal ID="CountryLiteral" runat="server" Text='<%# Eval("Address.Country.Country1") %>' />
            </ItemTemplate>
        </telerik:GridTemplateColumn>
        <telerik:GridBoundColumn DataField="Sales" DataType="System.Decimal"
            HeaderText="Sales" SortExpression="Sales" UniqueName="Sales">
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn DataField="Notes" HeaderText="Notes"
            SortExpression="Notes" UniqueName="Notes">
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn AllowFiltering="False" DataField="Website"
            HeaderText="Website" SortExpression="Website" UniqueName="Website">
        </telerik:GridBoundColumn>
 
        <telerik:GridBoundColumn AllowFiltering="False" DataField="ProfileID"
            HeaderText="AuthNet ProfileID" SortExpression="ProfileID" UniqueName="ProfileID">
        </telerik:GridBoundColumn>
                <telerik:GridBoundColumn AllowFiltering="False" DataField="LastUpdated"
            DataType="System.DateTime" HeaderText="LastUpdated"
            SortExpression="LastUpdated" UniqueName="LastUpdated">
        </telerik:GridBoundColumn>
    </Columns>
    <DetailTables>
        <telerik:GridTableView AutoGenerateColumns="true" DataKeyNames="ID,CompanyID"  AllowFilteringByColumn="false" Caption="Addresses" AllowSorting="false" DataSourceID="AddressesDataSource">
            <ParentTableRelation>
                <telerik:GridRelationFields DetailKeyField="CompanyID" MasterKeyField="ID"  />
            </ParentTableRelation>
        </telerik:GridTableView>
    </DetailTables>
</MasterTableView>
</telerik:RadGrid>
 
    <asp:LinqDataSource ID="CompaniesDataSource" runat="server"  EnableObjectTracking="true"
        ContextTypeName="admin.MTSDataClassesDataContext" EntityTypeName=""
        TableName="Companies" EnableInsert="True" EnableUpdate="True">
    </asp:LinqDataSource>
 
    <asp:LinqDataSource ID="AddressesDataSource" runat="server"
    ContextTypeName="admin.MTSDataClassesDataContext" EntityTypeName=""
    TableName="Addresses" EnableInsert="true" EnableUpdate="true" Where="CompanyID==@ID">
        <WhereParameters>
            <asp:Parameter Name="ID" Type="Int32"  />
        </WhereParameters>
    </asp:LinqDataSource>
 
    <telerik:RadAjaxManager runat="server">
        <AjaxSettings>
            <telerik:AjaxSetting AjaxControlID="CompaniesGrid">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="CompaniesGrid" UpdatePanelHeight="" />
                </UpdatedControls>
            </telerik:AjaxSetting>
        </AjaxSettings>
    </telerik:RadAjaxManager>

Thanks,

Rick

0
Rick New
Top achievements
Rank 1
answered on 07 Oct 2010, 03:51 AM
Changed the Where from:
Where="CompanyID == @ID">
<asp:Parameter Name="ID" Type="Int32"  />
to:
Where="CompanyID == @CompanyID">
<asp:Parameter Name="CompanyID" Type="Int32"  />
and it worked. I'm confused where the query is getting the @CompanyID value since the DataKeyNames in the CompaniesDataSource are "ID,PrmaryAddressID" and the CompaniesDataSource holds the needed where value. What am I missing?
0
Accepted
Pavlina
Telerik team
answered on 07 Oct 2010, 04:39 PM
Hi Rick New,

The DetailKeyField property is the name of a field in the data source of the child table whose value must match the parent field specified by MasterKeyField. When you are using declarative data sources, this string must match exactly the name of a SELECT / WHERE parameter in the detail table view's data source. In your case the DetailKeyField property of the ParentTableRelation collection is CompanyID, therefore after you set Where parameter to "CompanyID == @CompanyID"  everything is working as expected.

Please review the help article below for more information about declarative relations in hierarchy grid:
http://www.telerik.com/help/aspnet-ajax/grdhierarchicaldatabindingusingneeddatasource.html

Best wishes,
Pavlina
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Grid
Asked by
Rick New
Top achievements
Rank 1
Answers by
Pavlina
Telerik team
Rick New
Top achievements
Rank 1
Share this question
or