Binding DetailTable to List<> in MasterTable DataSource

3 posts, 0 answers
  1. John Mann
    John Mann avatar
    38 posts
    Member since:
    Nov 2008

    Posted 12 Jan 2017 Link to this post

    I am using a custom class as the DataSource for a radgrid. My class has a structure like this (greatly simplified).


    public class Batch
      public Batch() { }
      public int BatchID { get; set; }
      public string FirstName { get; set; }
      public string MiddleName { get; set; }
      public string LastName { get; set; }
      public DateTime BatchDate { get; set; }
      public List<Payment> Payments { get; set; }
    public class Payment
      public Payment() { }
      public int PaymentID { get; set; }
      public string CheckNumber { get; set; }
      public decimal Amount { get; set; }

    My grid is defined like this.

    <telerik:RadGrid ID="RadGrid1" runat="server">
      <mastertableview datakeynames="BatchID">
          <telerik:GridBoundColumn DataField="FirstName" HeaderText="First Name" UniqueName="gbcFirstName" />
          <telerik:GridBoundColumn DataField="MiddleName" HeaderText="Middle Name" UniqueName="gbcMiddleName" />
          <telerik:GridBoundColumn DataField="LastName" HeaderText="Last Name" UniqueName="gbcLastName" />
          <telerik:GridBoundColumn DataField="BatchDate" HeaderText="Batch Date" UniqueName="gbcBatchDate" />
          <telerik:GridTableView runat="server" HierarchyLoadMode="ServerBind" Name="gtvPayments" DataKeyNames="Payments.BatchID">
              <telerik:GridRelationFields MasterKeyField="BatchID" DetailKeyField="Payments.BatchID" />
              <telerik:GridBoundColumn DataField="Payments.CheckNumber" HeaderText="Check Number" UniqueName="gbcCheckNumber" />
              <telerik:GridNumericColumn DataField="Payments.Amount" HeaderText="Amount" UniqueName="gncAmount" />


    I assign the datasource to the grid in the NeedDataSource event.

    void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
      List<Batch> batch = new List<Batch>(1500);
      RadGrid1.DataSource = batch;

    Since each row in the master table datasource contains a list of its detail items is it possible to create a Master/Detail grid relationship directly from this or do I need to do something in the DetailTableDataBind event?


  2. Pavlina
    Pavlina avatar
    6187 posts

    Posted 17 Jan 2017 Link to this post


    Find attached a sample page which shows how you can achieve the desired functionality. Give it a try and let me know if you need additional assistance.

    Telerik by Progress
    Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
  3. John Mann
    John Mann avatar
    38 posts
    Member since:
    Nov 2008

    Posted 26 Jan 2017 in reply to Pavlina Link to this post

    Thank you, Pavlina. Yes, that works and is the way I have done it previously, but I was hoping that since each row of my data source contains it's own detail information that there would be a way to do the bind declaratively.


Back to Top