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" />
Web. HttpException: A field or property with name 'Service Id~~101' was not found in the selected data source. Possible causes of this error may be the following: an incorrect or case-insensitive spelling of the grid column name; assigning a wrong or not properly initialized data source to the grid.
The BoundField class is used by data-bound controls (such as GridView and DetailsView) to display the value of a field as text. The BoundField object is displayed differently depending on the data-bound control in which it is used.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With