When inserting a record on a sub grid in a two grid hierarchy using linq data sources and auto inserts/updates/deletes I'm getting a 0 for the parent record's id, which throws an error and doesn't insert the new record.
Editing and deleting work fine, but not inserting. I can manually override the insert command, check to see if it's the sub grid that's inserting, retrieve the id of the parent, and insert the record. But the auto Linq functionality doesn't work for me.
I've tried this many different ways and I can't seem to get this functionality to fly (inserting a record on a hierarchical sub grid with Linq auto method) in any configuration.
Code:
<telerik:RadGrid ID="ItemsGrid" Width="100%" Height="100%" Skin="Telerik" DataSourceID="ItemsDataSource" runat="server" AllowPaging="True" AllowSorting="true" PageSize="14" AutoGenerateColumns="false"
AllowAutomaticInserts="true" AllowAutomaticUpdates="true" AllowAutomaticDeletes="true">
<MasterTableView Width="100%" CommandItemDisplay="Top" DataKeyNames="Id"
EditMode="EditForms" AutoGenerateColumns="False">
<DetailTables>
<telerik:GridTableView DataKeyNames="Id, ItemId" DataSourceID="ItemCategoriesDataSource" Width="100%" CommandItemDisplay="Top" AutoGenerateColumns="false" runat="server">
<ParentTableRelation>
<telerik:GridRelationFields DetailKeyField="ItemId" MasterKeyField="Id" />
</ParentTableRelation>
<Columns>
<telerik:GridEditCommandColumn ButtonType="ImageButton" HeaderStyle-Width="20px" />
<telerik:GridBoundColumn DataField="Id" SortExpression="ItemCategoryId" UniqueName="ItemCategoryId" ReadOnly="true" Visible="false" />
<telerik:GridBoundColumn DataField="ItemId" SortExpression="ItemId" UniqueName="ItemId" ReadOnly="true" Visible="false" />
<telerik:GridBoundColumn DataField="Name" SortExpression="Name" UniqueName="Name" HeaderText="Name" />
<telerik:GridBoundColumn DataField="DateEntered" HeaderText="DateEntered" SortExpression="DateEntered" UniqueName="DateEntered" ReadOnly="true" DataFormatString="{0:d}" />
<telerik:GridButtonColumn ConfirmText="Delete this item?" ButtonType="ImageButton" CommandName="Delete" Text="Delete" />
</Columns>
</telerik:GridTableView>
</DetailTables>
<Columns>
<telerik:GridEditCommandColumn ButtonType="ImageButton" HeaderStyle-Width="20px" />
<telerik:GridBoundColumn DataField="Id" SortExpression="ItemId" HeaderText="ItemId" UniqueName="ItemId" ReadOnly="true" />
<telerik:GridBoundColumn DataField="Name" SortExpression="Name" UniqueName="Name" HeaderText="Name" />
<telerik:GridBoundColumn DataField="DateEntered" HeaderText="DateEntered" SortExpression="DateEntered" UniqueName="DateEntered" ReadOnly="true" DataFormatString="{0:d}" />
<telerik:GridButtonColumn ConfirmText="Delete this item?" ButtonType="ImageButton" CommandName="Delete" Text="Delete" />
</Columns>
</MasterTableView>
</telerik:RadGrid>
<asp:LinqDataSource ID="ItemsDataSource" ContextTypeName="AppDataContext" TableName="Items"
EnableInsert="true" EnableUpdate="true" EnableDelete="true" runat="server" />
<asp:LinqDataSource ID="ItemCategoriesDataSource" ContextTypeName="AppDataContext" TableName="ItemCategories"
EnableInsert="true" EnableUpdate="true" EnableDelete="true" Where="ItemId == @ItemId" runat="server">
<WhereParameters>
<asp:Parameter Name="ItemId" Type="Int32" />
</WhereParameters>
</asp:LinqDataSource>
Any thoughts are greatly appreciated,
Seth
Editing and deleting work fine, but not inserting. I can manually override the insert command, check to see if it's the sub grid that's inserting, retrieve the id of the parent, and insert the record. But the auto Linq functionality doesn't work for me.
I've tried this many different ways and I can't seem to get this functionality to fly (inserting a record on a hierarchical sub grid with Linq auto method) in any configuration.
Code:
<telerik:RadGrid ID="ItemsGrid" Width="100%" Height="100%" Skin="Telerik" DataSourceID="ItemsDataSource" runat="server" AllowPaging="True" AllowSorting="true" PageSize="14" AutoGenerateColumns="false"
AllowAutomaticInserts="true" AllowAutomaticUpdates="true" AllowAutomaticDeletes="true">
<MasterTableView Width="100%" CommandItemDisplay="Top" DataKeyNames="Id"
EditMode="EditForms" AutoGenerateColumns="False">
<DetailTables>
<telerik:GridTableView DataKeyNames="Id, ItemId" DataSourceID="ItemCategoriesDataSource" Width="100%" CommandItemDisplay="Top" AutoGenerateColumns="false" runat="server">
<ParentTableRelation>
<telerik:GridRelationFields DetailKeyField="ItemId" MasterKeyField="Id" />
</ParentTableRelation>
<Columns>
<telerik:GridEditCommandColumn ButtonType="ImageButton" HeaderStyle-Width="20px" />
<telerik:GridBoundColumn DataField="Id" SortExpression="ItemCategoryId" UniqueName="ItemCategoryId" ReadOnly="true" Visible="false" />
<telerik:GridBoundColumn DataField="ItemId" SortExpression="ItemId" UniqueName="ItemId" ReadOnly="true" Visible="false" />
<telerik:GridBoundColumn DataField="Name" SortExpression="Name" UniqueName="Name" HeaderText="Name" />
<telerik:GridBoundColumn DataField="DateEntered" HeaderText="DateEntered" SortExpression="DateEntered" UniqueName="DateEntered" ReadOnly="true" DataFormatString="{0:d}" />
<telerik:GridButtonColumn ConfirmText="Delete this item?" ButtonType="ImageButton" CommandName="Delete" Text="Delete" />
</Columns>
</telerik:GridTableView>
</DetailTables>
<Columns>
<telerik:GridEditCommandColumn ButtonType="ImageButton" HeaderStyle-Width="20px" />
<telerik:GridBoundColumn DataField="Id" SortExpression="ItemId" HeaderText="ItemId" UniqueName="ItemId" ReadOnly="true" />
<telerik:GridBoundColumn DataField="Name" SortExpression="Name" UniqueName="Name" HeaderText="Name" />
<telerik:GridBoundColumn DataField="DateEntered" HeaderText="DateEntered" SortExpression="DateEntered" UniqueName="DateEntered" ReadOnly="true" DataFormatString="{0:d}" />
<telerik:GridButtonColumn ConfirmText="Delete this item?" ButtonType="ImageButton" CommandName="Delete" Text="Delete" />
</Columns>
</MasterTableView>
</telerik:RadGrid>
<asp:LinqDataSource ID="ItemsDataSource" ContextTypeName="AppDataContext" TableName="Items"
EnableInsert="true" EnableUpdate="true" EnableDelete="true" runat="server" />
<asp:LinqDataSource ID="ItemCategoriesDataSource" ContextTypeName="AppDataContext" TableName="ItemCategories"
EnableInsert="true" EnableUpdate="true" EnableDelete="true" Where="ItemId == @ItemId" runat="server">
<WhereParameters>
<asp:Parameter Name="ItemId" Type="Int32" />
</WhereParameters>
</asp:LinqDataSource>
Any thoughts are greatly appreciated,
Seth