この問題に関して多くの質問がありますが、私は特定の問題に対処していません。グリッドビューで編集可能なEntitySetがあります。それはうまく表示されます。しかし、私は外部キーの関係を処理するためにバインドされている2つのドロップダウンを持っています。これは、挿入するために同じページ上のフォームビューで機能します。そして、ある時点で、私はグリッドの編集ビューで作業していました。GridViewのEditItemTemplate内のEntityDataSourceにDropDownListをバインドします
これはASP.Net 3.5(Entity Framework 1)にあります。 Julie LermanのEntity Framework Book(Ch 11)の286ページの例を使用しました。
エラーは、 "Eval()、XPath()、およびBind()などのデータバインディングメソッドは、データバインドされたコントロールのコンテキストでのみ使用できます。
私がこれで見つけたほとんどの投稿は、評価、結合に関連しています。コードは表示モード(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>
後のページで、私は、インサートと連携FormViewコントロールがあります:私はフォーマットすることができるように
<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>
私はその本から関連するサンプルを開きました(第1版とサンプルは3.5ですので、VS2008を使用して実行しています)。 –