GridViews中的实体外键 [英] Entity Foreign Keys in GridViews

查看:49
本文介绍了GridViews中的实体外键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有人能够找到一个干净的解决方案来使用EntityDataSource在GridView中显示外键值?

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

例如,我的员工表中有一个(FK )JobTitleID,我希望Employees GridView显示职务标题列。

For example, my Employees table has a (FK)JobTitleID and I want the Employees GridView to display a Job Title column.

推荐答案

您可以将值绑定到TemplateField。在内部,您可以使用适合您数据类型的任何类型的Bind控件。这是一个示例:

You can use bind the value to an TemplateField. Inside you can use whatever type of Bind control that is suitable for you type of data. 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>

我使用了 JobTitle.Name JobTitleID 连接到 JobTitle 实体。

I have used JobTitle.Name supposing that the JobTitleID is connected to JobTitle entity.

这篇关于GridViews中的实体外键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆