2

In ASP.Net 4.5 Web Forms, I have a grid which uses the new Model Binding feature, backed from Entity Framework:

<asp:GridView runat="server" ID="uxGrid" ItemType="SAData.SelfAssessment" DataKeyNames="SelfAssessmentID" AllowPaging="True" AllowSorting="True" PageSize="2"
        SelectMethod="GetSelfAssessments" CellPadding="5" ForeColor="#333333" GridLines="None" AutoGenerateColumns="False">

This duly lists out all Assessments within the DB, including their destination, which is a FK to the obviously-named Destination table. The DynamicField is set to display the DestinationID, but I really want to see the Destination name from the actual Destination table.

I've tried a couple of variations, e.g.

<asp:DynamicField DataField="Destinations.DestinationDescription" HeaderText="Destination" />

(where Destinations is the table)

and

<asp:DynamicField DataField="Destination.DestinationDescription" HeaderText="Destination" />

(where Destination is the Navigation property).

Both methods result in "The table 'SelfAssessment' does not have a column named 'Destinations.DestinationDescription'." or similar.

My GetSelfAssessments method uses the .Include method to, well, include the Destinations table, but to no avail.

Any thoughts?

Mike Kingscott
  • 477
  • 1
  • 5
  • 19

1 Answers1

0

Ok, fixed it - use a asp:BoundField to Destination.DestinationDescription, not a asp:DynamicField and it's fine. Also, there was no need to .Include("Destination") either, although I wonder whether I should to prevent an assumed lazy load.

Now, sorting on Destination is another matter...

Mike Kingscott
  • 477
  • 1
  • 5
  • 19