この問題に関して多くの質問がありますが、私が特定した問題に対処できるものはないと思います。グリッドビューを介して編集可能な EntitySet があります。正常に表示されています。ただし、外部キーの関係を処理するためにバインドされた 2 つのドロップダウンがあります。これは、挿入のために同じページのフォームビューで機能します。そして、ある時点で、グリッドの編集ビューでこれを機能させました。
これは ASP.Net 3.5 (Entity Framework 1) にあります。Julie Lerman の Entity Framework Book (Ch 11) の 286 ページの例を使用しました。
私が得ているエラーは、「Eval()、XPath()、Bind() などのデータバインディング メソッドは、データバインドされたコントロールのコンテキストでのみ使用できます」です。
この記事で見つけたほとんどの投稿は、Bind ではなく Eval に関連しています。コードは表示モード (Eval はラベルになります) で動作しますが、編集モードに切り替えるとエラーが発生します。
どんな助けでも大歓迎です。もっと情報を提供できるかどうか教えてください。
<asp:EntityDataSource
ID="dsChargePrintMappings"
ConnectionString="name=RateModelConnectionString"
DefaultContainerName="RateEntities"
EntitySetName="ChargePrintMappings"
Include="ChargeType, BillPrintGroup"
OrderBy="it.[EffectiveDate], it.[EffectiveEndDate]"
EnableDelete="true"
EnableUpdate="true"
EnableInsert="true"
runat="server" />
<asp:EntityDataSource
ID="dsChargeType"
ConnectionString="name=RateModelConnectionString"
DefaultContainerName="RateEntities"
EntitySetName="ChargeTypes"
runat="server" />
<asp:GridView
ID="gvChargePrintMappings"
DataSourceID="dsChargePrintMappings"
DataKeyNames="Id"
AutoGenerateColumns="false"
runat="server">
<AlternatingRowStyle CssClass="alternate" />
<Columns>
<asp:BoundField HeaderText="Id" ReadOnly="true" DataField="Id"
/>
<asp:TemplateField HeaderText="Charge Type">
<ItemTemplate>
<asp:Label ID="lbRate" Text='<%# Eval
("ChargeType.Description") %>' runat="server" />
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList
ID="ddChargeType"
DataSourceId="dsChargeType"
DataTextField="Description"
DataValueField="Id"
SelectedValue='<%# Bind("ChargeType.Id") %>'
AppendDataBoundItems="True"
runat="server">
<asp:ListItem Selected="True" Value="">(none)</asp:
ListItem>
</asp:DropDownList>
</EditItemTemplate>
</asp:TemplateField>
ページの後半には、挿入で機能するフォームビューがあります。
<asp:FormView ID="fvRate" DataSourceID="dsForm" DefaultMode="ReadOnly"
runat="server">
<EmptyDataTemplate>
<asp:Button ID="btnInsert" Text="Create New" CommandName="New"
runat="server" />
</EmptyDataTemplate>
<InsertItemTemplate>
<asp:Label ID="lblEffectiveDate" Text="Effective Date:"
AssociatedControlID="txtEffectiveDate" runat="server" />
<asp:TextBox ID="txtEffectiveDate" onfocus="$(this).datepicker ()" Text='<%# Bind("EffectiveDate") %>' runat="server" /><br>
<asp:Label ID="lblEffectiveEndDate" Text="Effective End Date:"
AssociatedControlID="txtEffectiveEndDate" runat="server" />
<asp:TextBox ID="txtEffectiveEndDate" onfocus="$ (this).datepicker()" Text='<%# Bind("EffectiveEndDate") %>' runat="server"
/><br>
<asp:Label ID="lblChargeType" Text="Charge Type:"
AssociatedControlID="ddChargeType" runat="server" />
<asp:DropDownList
ID="ddChargeType"
DataSourceId="dsChargeType"
DataTextField="Description"
DataValueField="Id"
SelectedValue='<%# Bind("ChargeType.Id") %>'
AppendDataBoundItems="True"
runat="server">
<asp:ListItem Selected="True" Value="">(none)</asp:ListItem
>
</asp:DropDownList><br>
<asp:Label ID="lblBillPrintGroup" Text="Bill Print Group:"
AssociatedControlID="ddBillPrintGroup" runat="server" />
<asp:DropDownList
ID="ddBillPrintGroup"
DataSourceId="dsBillPrintGroup"
DataTextField="Description"
DataValueField="Id"
SelectedValue='<%# Bind("BillPrintGroup.Id") %>'
AppendDataBoundItems="True"
runat="server">
<asp:ListItem Selected="True" Value="">(none)</asp:ListItem
>
</asp:DropDownList><br>
<asp:Button ID="btnInsert" CommandName="Insert" Text="Create"
runat="server" />
<asp:Button ID="btnCancelUpdate" CommandName="Cancel" Text ="Cancel" runat="server" />
</InsertItemTemplate>
</asp:FormView>