Entity Foreign Keys in GridViews

Has anyone been able to find a clean solution to display a foreign key value in a GridView using EntityDataSource?

For example, the My Employees table has the JobTitleID (FK) identifier, and I want the GridView Employees to display the job column.

0
source share
2 answers

You can use value binding to TemplateField. Inside, you can use any type of Bind control suitable for your data type. Here is an example:

<asp:GridView ID="gvEmployees" runat="server" AllowSorting="true" AutoGenerateColumns="false" DataKeyNames="ID" DataSourceID="godsCourses">
    <Columns>
        <asp:TemplateField HeaderText="Job Title">
            <ItemTemplate>
                <asp:Literal ID="hlProgram" runat="server" Text='<%# Bind("JobTitle.Name") %>' />
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
</asp:GridView>

I used JobTitle.Name, believing that it JobTitleIDis associated with an object JobTitle.

+1
source

, , . , Include EntityDataSource. , EntityDataSorce " ", HTML.

MSDN.

PS. , Eval, , , Eval Bind .

+2

All Articles