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
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
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
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