Declarative binding for a master detail grid

3 posts, 0 answers
  1. andieje
    andieje avatar
    473 posts
    Member since:
    Oct 2006

    Posted 28 Jul 2009 Link to this post

    Hi

    I am using declarative binding for a master detail grid. The basic set up is a master table based on a table called Customers with a primary key CustomerID and a detail table based on a database table called Vehicles with primary key Reg and foreign key CustomerID.

    The grid has this set up
    <telerik:RadGrid DataSourceID="EsDataSource1" ID="RadGrid1" runat="server" AllowAutomaticUpdates="true">  
            <MasterTableView DataSourceID="EsDataSource1" DataKeyNames="CustomerID" AutoGenerateColumns="FALSE">  
         
            <DetailTables> 
    <telerik:GridTableView DataSourceID="EsDataSource2" AutoGenerateColumns="false" Name="Vehicles" DataKeyNames="Reg" ShowFooter="false">  
     <ParentTableRelation> 
       <telerik:GridRelationFields DetailKeyField="Reg" MasterKeyField="CustomerID" /> 
    </ParentTableRelation> 
     

    I am binding this grid using a third party data source. The code to populate the details table basically retrieves all of the records in the Vehicles table and then the RadGrid filters these to show only those belonging to the parent row. Naturally i would prefer to retrieve only those records from the Vehicles table belonging to the parent row in the first place. How can i access the id of the of the current row in the master table in the code behind and pass it to the data source. This is what i have had to do

     Protected Sub RadGrid1_DetailTableDataBind(ByVal source As Object, ByVal e As Telerik.Web.UI.GridDetailTableDataBindEventArgs) Handles RadGrid1.DetailTableDataBind  
            Dim dataItem As GridDataItem = CType(e.DetailTableView.ParentItem, GridDataItem)  
            customerID = dataItem.GetDataKeyValue("CustomerID").ToString()  <======set foreign key in page variable  
     
        End Sub  
     
     
     
     
    DATA SOURCE FOR THE DETAILS TABLE  
       Protected Sub EsDataSource2_esSelect(ByVal sender As Object, ByVal e As EntitySpaces.Web.esDataSourceSelectEventArgs) Handles EsDataSource2.esSelect  
            
            Dim coll As New VehiclesCollection  
            Dim query As New VehiclesQuery  
            query.Where(query.CustomerID = customerID)  <==== page variable  
            coll.Load(query)  
            e.Collection = coll 
        End Sub 

    I am using the data source rather than just binding programmatically because the grid uses an edit form template and the data source will perform the updates automatically for me.

    thanks
  2. Kiara
    Kiara avatar
    309 posts
    Member since:
    Jul 2006

    Posted 31 Jul 2009 Link to this post

    From what I learned about the Telerik grid, you should either build your parent relations declarative or use programmatic solution wiring the DetailTableDataBind event. The first two live demos under the 'Hierarchy' node and the help topics linked in their descriptions give this information - check them out and organize your code as said there.

    Kiara
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. andieje
    andieje avatar
    473 posts
    Member since:
    Oct 2006

    Posted 07 Aug 2009 Link to this post

    Hi

    I can't do that because I am using a third party data source. As far as I am aware data sources as a whole don't have a standard api for hooking up to binding events for detail tables so you have to use a workaround.
Back to Top