A field or property with the name was not found in the selected data source

I have an entity data model with two objects in it, Roles and Users. I have a navigation property, I have EntityDataSource and GridView. EntityDataSource points to a Users object and has an Include = "Roles" parameter.

I added a BoundField to the GridView, which points to RoleName, a property of object roles. However, when I execute the code, I get the above error.

I have successfully used very similar code in another application. Any ideas why this is not working?

Here is my 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> 

And here is the BoundField:

 <asp:BoundField DataField="RoleName" HeaderText="Role" SortExpression="RoleName" /> 
+6
source share
1 answer

You cannot use asp:BoundField for a property of the corresponding navigation property. You can only use asp:TemplateField and then bind it as readonly with Eval ( not Bind ). BoundFields always use Bind internally, so the reason does not work. I had to figure it out myself some time ago:

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

+20
source

Source: https://habr.com/ru/post/886014/


All Articles