Henrik Berg Andersen
2010-07-05 15:01:38 UTC
I made a fairly simple user control (ascx) in Visual Studio that uses a
dataset in Dynamics AX 2009 with 2 data sources on it: PurchLine and my
table, PurchEXWPackingList, that has the InventTransId as key. It ALWAYS
gives me the same error in the eventlog:
"The given key was not present in the dictionary.
System.Collections.Generic.KeyNotFoundException
at System.ThrowHelper.ThrowKeyNotFoundException()
at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
at System.Collections.ObjectModel.KeyedCollection`2.get_Item(TKey key)
... bla bla bla"
There is no clue whatsoever in the message that says where the error is in
the design.
If I simplify the dataset even more and have just PurchEXWPackingList as the
one datasource in it and in the Visual Studio have just one axForm with one
axGrid then it works fine. However, I would like the user of the web page to
be aware what purchase order line the data is related to and thus I would
like to show a couple of fields from PurchLine also. This of course means
that I will have to put PurchLine in the dataset also.
The design in Visual Studio then becomes just a little bit more complicated
becuase I use multiple sections. One section for the PurchLine fields and
once section with the axGrid showing fields from PurchEXWPackingList. I mean
.. how hard can that be?
So far I have not succeeded in beating this quite annoying error. I tried
changing the datakeynames property in the axForms in the design. I tried
omitting them altogether. I tried erasing the whole thing and start from
scratch. Nothing works. If I run the webpage in enterprise portal it just
says "An unexpected error" and the eventlog comes up with that
KeyNotFoundExeption but I do not know that key it is trying to look for or
what it wants me to do.
I also tried to open EPPurchTableEdit.ascx to get inspiration and mimic
that code exactly but that does not work either on my page even though
EPPurchTableEdit also uses multiplesections.
Anyone tried this and found a solution? I would have liked to add pictures
but I cannot in this forum for some reason. Below you can find my code from
Visual Studio.
--
Kind regards,
Henrik Berg Andersen
--
Code from Visual Studio:
<%@ Control Language="C#" AutoEventWireup="true"
CodeFile="EPPurchEXWPackingList.ascx.cs" Inherits="EPPurchEXWPackingList" %>
<%@ Register Assembly="Microsoft.Dynamics.Framework.Portal, Version=5.0.0.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35"
Namespace="Microsoft.Dynamics.Framework.Portal.UI.WebControls"
TagPrefix="dynamics" %>
<dynamics:AxDataSource ID="dsEPPurchEXWPackingList" runat="server"
DataSetName="EPPurchEXWPackingList" ProviderView="">
</dynamics:AxDataSource>
<dynamics:AxMultiSection ID="multiPurchEXW" runat="server">
<dynamics:AxSection ID="sectionPurchase" runat="server">
<dynamics:AxForm ID="formPurchase" runat="server"
DataMember="PurchLine_Current"
DataSourceID="dsEPPurchEXWPackingList"
DataKeyNames="InventTransId">
<dynamics:AxGroup ID="PurchaseGroup" runat="server" Caption="<%$
AxLabel:@SYS25545 %>">
<Fields>
<dynamics:AxBoundField DataField="PurchaseId"
DataSet="EPPurchEXWPackingList" DataSetView="PurchLine" ReadOnly="true">
</dynamics:AxBoundField>
<dynamics:AxBoundField DataField="Name"
DataSet="EPPurchEXWPackingList" DataSetView="PurchLine"
ReadOnly="true"></dynamics:AxBoundField>
</Fields>
</dynamics:AxGroup>
</dynamics:AxForm>
</dynamics:AxSection>
<dynamics:AxSection ID="sectionPurchEXW" runat="server" Caption="<%$
axlabel:@PIN211 %>">
<dynamics:AxForm ID="formPurchEXWPackingList" runat="server"
AutoGenerateInsertButton="True" AutoGenerateEditButton="False"
DefaultMode="Insert" InsertText="<%$ axlabel:@SYS103443 %>"
CancelText="<%$ axlabel:@SYS12483 %>">
<dynamics:AxGridView ID="gridPurchEXW" runat="server"
AllowDelete="True"
AllowEdit="True" DataKeyNames="RecId"
DataMember="PurchEXWPackingList"
DataSourceID="dsEPPurchEXWPackingList" CellPadding="4"
ForeColor="#333333"
GridLines="None" EmptyDataText="<%$ axlabel:@SYS36901 %>"
caption="<%$ axlabel:@PIN211 %>">
<HeaderStyle BackColor="#1C5E55" Font-Bold="True"
ForeColor="White" />
<EditRowStyle VerticalAlign="Top" BackColor="#7C6F57" />
<PagerStyle BackColor="#666666" ForeColor="White"
HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True"
ForeColor="#333333" />
<AlternatingRowStyle BackColor="White" />
<Columns>
<dynamics:AxBoundFieldGroup
DataSet="EPPurchEXWPackingList"
DataSetView="PurchEXWPackingList"
FieldGroup="WebPackingListGrid" AutoPostBack="False">
</dynamics:AxBoundFieldGroup>
</Columns>
<FooterStyle BackColor="#1C5E55" Font-Bold="True"
ForeColor="White" />
<RowStyle VerticalAlign="Top" BackColor="#E3EAEB" />
</dynamics:AxGridView>
</dynamics:AxForm>
</dynamics:AxSection>
</dynamics:AxMultiSection>
dataset in Dynamics AX 2009 with 2 data sources on it: PurchLine and my
table, PurchEXWPackingList, that has the InventTransId as key. It ALWAYS
gives me the same error in the eventlog:
"The given key was not present in the dictionary.
System.Collections.Generic.KeyNotFoundException
at System.ThrowHelper.ThrowKeyNotFoundException()
at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
at System.Collections.ObjectModel.KeyedCollection`2.get_Item(TKey key)
... bla bla bla"
There is no clue whatsoever in the message that says where the error is in
the design.
If I simplify the dataset even more and have just PurchEXWPackingList as the
one datasource in it and in the Visual Studio have just one axForm with one
axGrid then it works fine. However, I would like the user of the web page to
be aware what purchase order line the data is related to and thus I would
like to show a couple of fields from PurchLine also. This of course means
that I will have to put PurchLine in the dataset also.
The design in Visual Studio then becomes just a little bit more complicated
becuase I use multiple sections. One section for the PurchLine fields and
once section with the axGrid showing fields from PurchEXWPackingList. I mean
.. how hard can that be?
So far I have not succeeded in beating this quite annoying error. I tried
changing the datakeynames property in the axForms in the design. I tried
omitting them altogether. I tried erasing the whole thing and start from
scratch. Nothing works. If I run the webpage in enterprise portal it just
says "An unexpected error" and the eventlog comes up with that
KeyNotFoundExeption but I do not know that key it is trying to look for or
what it wants me to do.
I also tried to open EPPurchTableEdit.ascx to get inspiration and mimic
that code exactly but that does not work either on my page even though
EPPurchTableEdit also uses multiplesections.
Anyone tried this and found a solution? I would have liked to add pictures
but I cannot in this forum for some reason. Below you can find my code from
Visual Studio.
--
Kind regards,
Henrik Berg Andersen
--
Code from Visual Studio:
<%@ Control Language="C#" AutoEventWireup="true"
CodeFile="EPPurchEXWPackingList.ascx.cs" Inherits="EPPurchEXWPackingList" %>
<%@ Register Assembly="Microsoft.Dynamics.Framework.Portal, Version=5.0.0.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35"
Namespace="Microsoft.Dynamics.Framework.Portal.UI.WebControls"
TagPrefix="dynamics" %>
<dynamics:AxDataSource ID="dsEPPurchEXWPackingList" runat="server"
DataSetName="EPPurchEXWPackingList" ProviderView="">
</dynamics:AxDataSource>
<dynamics:AxMultiSection ID="multiPurchEXW" runat="server">
<dynamics:AxSection ID="sectionPurchase" runat="server">
<dynamics:AxForm ID="formPurchase" runat="server"
DataMember="PurchLine_Current"
DataSourceID="dsEPPurchEXWPackingList"
DataKeyNames="InventTransId">
<dynamics:AxGroup ID="PurchaseGroup" runat="server" Caption="<%$
AxLabel:@SYS25545 %>">
<Fields>
<dynamics:AxBoundField DataField="PurchaseId"
DataSet="EPPurchEXWPackingList" DataSetView="PurchLine" ReadOnly="true">
</dynamics:AxBoundField>
<dynamics:AxBoundField DataField="Name"
DataSet="EPPurchEXWPackingList" DataSetView="PurchLine"
ReadOnly="true"></dynamics:AxBoundField>
</Fields>
</dynamics:AxGroup>
</dynamics:AxForm>
</dynamics:AxSection>
<dynamics:AxSection ID="sectionPurchEXW" runat="server" Caption="<%$
axlabel:@PIN211 %>">
<dynamics:AxForm ID="formPurchEXWPackingList" runat="server"
AutoGenerateInsertButton="True" AutoGenerateEditButton="False"
DefaultMode="Insert" InsertText="<%$ axlabel:@SYS103443 %>"
CancelText="<%$ axlabel:@SYS12483 %>">
<dynamics:AxGridView ID="gridPurchEXW" runat="server"
AllowDelete="True"
AllowEdit="True" DataKeyNames="RecId"
DataMember="PurchEXWPackingList"
DataSourceID="dsEPPurchEXWPackingList" CellPadding="4"
ForeColor="#333333"
GridLines="None" EmptyDataText="<%$ axlabel:@SYS36901 %>"
caption="<%$ axlabel:@PIN211 %>">
<HeaderStyle BackColor="#1C5E55" Font-Bold="True"
ForeColor="White" />
<EditRowStyle VerticalAlign="Top" BackColor="#7C6F57" />
<PagerStyle BackColor="#666666" ForeColor="White"
HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True"
ForeColor="#333333" />
<AlternatingRowStyle BackColor="White" />
<Columns>
<dynamics:AxBoundFieldGroup
DataSet="EPPurchEXWPackingList"
DataSetView="PurchEXWPackingList"
FieldGroup="WebPackingListGrid" AutoPostBack="False">
</dynamics:AxBoundFieldGroup>
</Columns>
<FooterStyle BackColor="#1C5E55" Font-Bold="True"
ForeColor="White" />
<RowStyle VerticalAlign="Top" BackColor="#E3EAEB" />
</dynamics:AxGridView>
</dynamics:AxForm>
</dynamics:AxSection>
</dynamics:AxMultiSection>