Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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" 
    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" />
like image 276
Dave Mackey Avatar asked Apr 15 '11 18:04

Dave Mackey


People also ask

Was not found on the selected data source?

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.

What is BoundField in asp net?

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.


1 Answers

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

like image 129
Slauma Avatar answered Nov 03 '22 09:11

Slauma