gpt4 book ai didi

asp.net - 在所选数据源中找不到具有该名称的字段或属性

转载 作者:行者123 更新时间:2023-12-02 11:19:42 25 4
gpt4 key购买 nike

我有一个实体数据模型,其中有两个实体“角色”和“用户”。我有一个 EntityDataSource 和一个 GridView,其中有一个导航属性。 EntityDataSource 指向 Users 实体并具有 Include="Roles"参数。

我在 GridView 中添加了一个 BoundField,它指向 RoleName(实体 Roles 的属性)。但是,当我执行代码时,出现上述错误。

我在另一个应用程序中成功地使用了非常相似的代码。有什么想法为什么这不起作用吗?

这是我的EntityDataSource:

    <asp:EntityDataSource ID="EntityDataSource1" runat="server" 
ConnectionString="name=pbu_checklistEntities"
DefaultContainerName="pbu_checklistEntities" EnableDelete="True"
EnableFlattening="False" EnableUpdate="True" EntitySetName="Users" Include="Role">
</asp:EntityDataSource>

这是 BoundField:

<asp:BoundField DataField="RoleName" HeaderText="Role" SortExpression="RoleName" />

最佳答案

您不能将 asp:BoundField 用于相关导航属性的属性。您只能使用 asp:TemplateField,然后使用 Eval 将其绑定(bind)为只读(不能 Bind)。 BoundFields 始终在内部使用 Bind,这就是它不起作用的原因。我前段时间必须自己解决这个问题:

Columns of two related database tables in one ASP.NET GridView with EntityDataSource

关于asp.net - 在所选数据源中找不到具有该名称的字段或属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5680652/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com