Hi Bobby!
As mentioned in a private message, in the real code I am using, ForeignKeyName="ClientID" is there, and the probleme was elsewhere. However, now that I have fixed everything, it is still not working. When I do a trace, all the object properties are set in ExecuteInsert() except for clientID.
Here an excerpt of the code I am using. Sorry if it is a bit long. I wanted to make sure that all the necessary information was there. Please note that I have two FormViews: The first one in Edit Mode (The Client already exists in the database; it could also be in RaedOnly Mode). And the second one in Insert Mode. I set a One-To-One Relationship so that the ClientID is updated when inserting the ClientModule, but it does not seem to wrok properly. ClientModule.ClientID stays empty. At this point, I suspect there is really a bug... or maybe it is me who missed something.
<asp:FormView ID="ClientFormView" runat="server" DefaultMode="Edit"
DataSourceID="ClientDataSource" DataKeyNames="ClientID">
<EditItemTemplate>
...[SNIP]...
</EditItemTemplate>
</asp:FormView>
<asp:FormView ID="ClientModuleFormView" runat="server"
DefaultMode="Insert"
DataSourceID="ClientModuleDataSource" DataKeyNames="ClientModuleID"
OnItemInserting="OnModuleAjouterFormViewInserting"
>
<InsertItemTemplate>
...[SNIP]...
<asp:Button ID="InsertButton" runat="server" CausesValidation="True" CommandName="Insert" Text="Ajouter" />
<asp:Button ID="CancelButton" runat="server" CausesValidation="False" CommandName="Cancel" Text="Annuler" />
...[SNIP]...
</InsertItemTemplate>
</asp:FormView>
<data:OneToOneViewRelationship ID="ClientClientModuleRelationship" runat="server">
<PrimaryMember ID="PrimaryMember" runat="server"
DataSourceID="ClientDataSource"
ViewControlID="ClientFormView"
EntityKeyName="ClientID" />
<ReferenceMember ID="ReferenceMember" runat="server"
DataSourceID="ClientModuleDataSource"
ViewControlID="ClientModuleFormView"
EntityKeyName="ClientModuleID"
ForeignKeyName="ClientID"/>
</data:OneToOneViewRelationship>
<data:ClientDataSource ID="ClientDataSource" runat="server"
EnableDeepLoad="false" SelectMethod="GetByClientID">
<Parameters>
<asp:QueryStringParameter Name="ClientID" QueryStringField="id" Type="String" />
</Parameters>
</data:ClientDataSource>
<data:ClientModuleDataSource ID="ClientModuleDataSource" EnableDeepLoad="false"
OnInserting="ClientModuleInserting" runat="server">
</data:ClientModuleDataSource>
Best regards,
JF