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

Editing Hierarchical Sub Grid With LINQ Auto Methods - ID on Insert

2 Answers 61 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Seth
Top achievements
Rank 1
Seth asked on 13 Nov 2008, 11:01 PM
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


2 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 14 Nov 2008, 11:27 AM
Hello Seth,

You can refer to the following link which discusses a similar scenario where autoinsert fails when inserting into a detailtable using linq datasources.
AutoInsert into DetailTable fails when using LINQ

Thanks
Princy.
0
Seth
Top achievements
Rank 1
answered on 14 Nov 2008, 11:34 AM
Unfortunately that thread doesn't present a workable solution.

So it must be done manually then?

Seth
Tags
Grid
Asked by
Seth
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Seth
Top achievements
Rank 1
Share this question
or