Reputation: 4432
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"
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" />
Upvotes: 6
Views: 34231
Reputation: 177163
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
Upvotes: 20