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

32,977

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

Share:
32,977
Dave Mackey
Author by

Dave Mackey

Love to code: Python, JS, C#, PHP, SQL, VB.NET, HTML, CSS. In ancient days I coded in QuickBasic, ASP, and VBScript. I'm a friendly introvert with solid communication skills. I work hard and have refined problem solving skills. When I was younger I worked in a variety of industries (commercial fisherman, stone mason, lawn care, factory, custodial, youth leader). I settled on IT and have experience working in a startup, higher education, and with non-profits.

Updated on July 05, 2022

Comments

  • Dave Mackey
    Dave Mackey almost 2 years

    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" />
    
  • Dave Mackey
    Dave Mackey about 13 years
    Thanks! That is a great help.
  • pseudocoder
    pseudocoder over 11 years
    The linked question addresses the issue more generally but +1 for this question and answer since it came up in my search--the question is more directly related to the answer.
  • John Bledsoe
    John Bledsoe over 10 years
    This only seems to be true in IIS 6 and not IIS 7. Can anyone confirm or deny this difference?
  • Emeka
    Emeka about 10 years
    Yes John Bledsoe, I only ran in to this issue when trying to deploy a project I had developed on VS 2013/IIS 7 on a VS 2010/IIS 6 setup. I had no issues when testing in my VS 2013/IIS 7 environment. Converting everything to TemplateFields worked for me.