davemackey davemackey -4 years ago 70
Vb.net Question

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

I have an Entity Data Model with two entities in it "Roles" and "Users". There is a navigation property from I have a EntityDataSource and a GridView. The EntityDataSource points to the Users entity and has an Include="Roles" parameter.

I've added a BoundField in the GridView that points to RoleName, a property of the entity Roles. However, when I execute the code I get the above error.

I have used very similar code successfully in another application. Any ideas why this isn't working?

Here is my EntityDataSource:

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

And here is the BoundField:

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

Answer Source

You cannot use an asp:BoundField for a property of a related navigation property. You can only use an asp:TemplateField and then bind it as readonly with Eval (not Bind). BoundFields are always using Bind internally, that's the reason why it doesn't work. I had to figure this out myself some time ago:

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download