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

Declarative binding for a master detail grid

2 Answers 62 Views
Grid
This is a migrated thread and some comments may be shown as answers.
andieje
Top achievements
Rank 1
andieje asked on 28 Jul 2009, 07:23 PM
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 Answers, 1 is accepted

Sort by
0
Kiara
Top achievements
Rank 1
answered on 31 Jul 2009, 01:55 PM
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
0
andieje
Top achievements
Rank 1
answered on 07 Aug 2009, 11:23 AM
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.
Tags
Grid
Asked by
andieje
Top achievements
Rank 1
Answers by
Kiara
Top achievements
Rank 1
andieje
Top achievements
Rank 1
Share this question
or