Currently, one can link a detail (child) grid to a master (parent) grid using LINQ. First, two LingDataSources are established for each grid and then linked together using the WhereParameters of the detail (child) LinqDataSource to identifying the key fields which are then linked to the master grid using the SelectedValue field. One example from Northwind db is given below:
To insert items into the detail grid, one needs to write some VB or C# code to place into the DataSource's InsertParameters a default value equal the SelectedValue of the master grid. A recent update permits using RadGrid.SelectedValue['FieldName'] permitting use of a specific field linking the two grids. Such as:
In the definition of InsertParameters for LINQ, I should be able to avoid using VB code using a "codeless" method. For example, the LinqDataSource2 above should include the following
But I am not having success using this method. When I try to insert a new record into the details grid, the value of CustomerID is not transfered to database but a "Null" value is supplied so I must use the VB code to set the default value of each InsertParameter. Shouldn't the Insert, Update, Select, and Delete functions be able to access the RadGrid's SelectedValue fields? Is this an issue with LINQ or with RadGrid?
I really like using "codeless" and allowing the intelligence of the components to interact together. Please let me know where I my code is flawed.
<asp:LinqDataSource ID="LinqDataSource1" runat="server" |
ContextTypeName="NWExample.DataClasses1DataContext" |
EnableDelete="True" EnableInsert="True" EnableUpdate="True" TableName="Customers"> |
</asp:LinqDataSource> |
<asp:LinqDataSource ID="LinqDataSource2" runat="server" |
ContextTypeName="NWExample.DataClasses1DataContext" |
EnableDelete="True" EnableInsert="True" EnableUpdate="True" TableName="Orders" |
Where="CustomerID == @CustomerID"> |
<WhereParameters> |
<asp:ControlParameter ControlID="RadGrid1" Name="CustomerID" |
PropertyName="SelectedValues['CustomerID']" |
Type="String" /> |
</WhereParameters> |
</asp:LinqDataSource> |
To insert items into the detail grid, one needs to write some VB or C# code to place into the DataSource's InsertParameters a default value equal the SelectedValue of the master grid. A recent update permits using RadGrid.SelectedValue['FieldName'] permitting use of a specific field linking the two grids. Such as:
Protected Sub RadGrid1_InsertCommand(ByVal source As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles RadGrid1.InsertCommand |
If "Detail".Equals(e.Item.OwnerTableView.Name) Then |
Dim parentItem As Telerik.Web.UI.GridDataItem = DirectCast(e.Item.OwnerTableView.ParentItem, Telerik.Web.UI.GridDataItem) |
LinqDataSource2.InsertParameters("CustomerID").DefaultValue = parentItem.OwnerTableView.DataKeyValues(parentItem.ItemIndex)("CustomerID").ToString |
End If |
End Sub |
In the definition of InsertParameters for LINQ, I should be able to avoid using VB code using a "codeless" method. For example, the LinqDataSource2 above should include the following
<InsertParameters> |
<asp:ControlParameter ControlID="RadGrid1" Name="CustomerID" |
PropertyName="SelectedValues['CustomerID']" Type="String" /> |
</InsertParameters> |
But I am not having success using this method. When I try to insert a new record into the details grid, the value of CustomerID is not transfered to database but a "Null" value is supplied so I must use the VB code to set the default value of each InsertParameter. Shouldn't the Insert, Update, Select, and Delete functions be able to access the RadGrid's SelectedValue fields? Is this an issue with LINQ or with RadGrid?
I really like using "codeless" and allowing the intelligence of the components to interact together. Please let me know where I my code is flawed.