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

Master/Detail view in Grid

2 Answers 43 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jon
Top achievements
Rank 1
Jon asked on 02 Jul 2013, 09:51 AM
I am trying to establish a master/detail relationship in my grid.  For a reason I can not understand, the detail row appears in every master record.  Can someone please point me to my mistake?

Here is my code:

<MasterTableView DataKeyNames="ID" DataSourceID="sqlBidDetail" EditMode="InPlace" CommandItemDisplay="Top" HierarchyLoadMode="ServerBind">
     <DetailTables>
          <telerik:GridTableView runat="server" AllowSorting="False" AutoGenerateColumns="True" DataKeyNames="DescriptionDetailID,BidDetailID" DataSourceID="sqlDescriptionDetail" EditMode="InPlace" CommandItemDisplay="Top" HierarchyLoadMode="ServerBind">
                <ParentTableRelation>
                        <telerik:GridRelationFields DetailKeyField="tblDescriptionDetail.BidDetailID" MasterKeyField="ID" />
                </ParentTableRelation>
           </DetailTables>
</MasterTableView>

and my 2 SQL data sources.

<asp:SqlDataSource ID="sqlBidDetail" runat="server" ConnectionString="<%$ ConnectionStrings:dbBidManager %>"
SelectCommand="SELECT tblBidDetail.ID, tblBidDetail.BidID, tblBidDetail.ULAID, tblBidDetail.ProductID FROM tblBidDetail" />
 
<asp:SqlDataSource ID="sqlDescriptionDetail" runat="server" ConnectionString="<%$ ConnectionStrings:dbBidManager %>"
SelectCommand="SELECT tblDescriptionDetail.DescriptionDetailID, tblDescriptionDetail.BidDetailID, tblDescriptionDetail.DescriptionTypeID FROM tblDescriptionDetail" />

There is a FK relationship between tblDescriptionDetail.BidDetailID and tblBidDetail.ID.  Note though that
tblDescriptionDetail.DescriptionDetailID is the primary key in that table.

2 Answers, 1 is accepted

Sort by
0
Accepted
Jayesh Goyani
Top achievements
Rank 2
answered on 02 Jul 2013, 11:31 AM
Hello,

Please try with below code snippet.

Please check "sqlDescriptionDetail" in below code snippet.

<telerik:RadGrid ID="RadGrid1" runat="server" DataSourceID="sqlBidDetail">
       <MasterTableView DataKeyNames="ID" EditMode="InPlace" CommandItemDisplay="Top" HierarchyLoadMode="ServerBind">
           <DetailTables>
               <telerik:GridTableView runat="server" AllowSorting="False" AutoGenerateColumns="True"
                   DataKeyNames="DescriptionDetailID,BidDetailID" DataSourceID="sqlDescriptionDetail" EditMode="InPlace"
                   CommandItemDisplay="Top" HierarchyLoadMode="ServerBind">
                   <ParentTableRelation>
                       <telerik:GridRelationFields DetailKeyField="BidDetailID" MasterKeyField="ID" />
                   </ParentTableRelation>
               </telerik:GridTableView>
           </DetailTables>
       </MasterTableView>
   </telerik:RadGrid>
   <asp:SqlDataSource ID="sqlBidDetail" runat="server" ConnectionString="<%$ ConnectionStrings:JayeshTestConnectionString %>"
       SelectCommand="SELECT [ID], [BidID], [ULAID], [ProductID] FROM [tblBidDetail]">
   </asp:SqlDataSource>
   <asp:SqlDataSource ID="sqlDescriptionDetail" runat="server" ConnectionString="<%$ ConnectionStrings:JayeshTestConnectionString %>"
       SelectCommand="SELECT [DescriptionDetailID], [BidDetailID], [DescriptionTypeID] FROM [tblDescriptionDetail] WHERE ([BidDetailID] = @BidDetailID)">
       <SelectParameters>
           <asp:SessionParameter Name="BidDetailID" SessionField="BidDetailID" Type="Int32" />
       </SelectParameters>
   </asp:SqlDataSource>


Thanks,
Jayesh Goyani
0
Jon
Top achievements
Rank 1
answered on 02 Jul 2013, 11:56 AM
That did the trick!  I learned something new today too.  I did not know that the session variable would take on the value automatically.  Thanks much!
Tags
Grid
Asked by
Jon
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Jon
Top achievements
Rank 1
Share this question
or