在单个GridView列中显示多个表值

时间:2022-09-09 08:04:32

I have a GridView bound to a table using BindingSource and Linq to SQL classes. The table structure is like this:

我有一个使用BindingSource和Linq到SQL类绑定到表的GridView。表结构如下:

MainTable
----------
ID Name FormReserveId
123 asd 15

FormReserves
-----------------
ID FormId Number
15 33     some number

Forms
------
ID FormName
33 form name

MainTable.FormReserveId foreign key to FormReserves.ID

MainTable.FormReserveId FormReserves.ID的外键

FormReserves.FormId foreign key to Forms.ID

FormReserve.FormId Forms.ID的外键

In the grid, instead of displaying FormReserveId (e.g 15), how can I display "form name, some number"?

在网格中,如何显示“表单名称,某些数字”而不是显示FormReserveId(例如15)?

1 个解决方案

#1


1  

You need to either 'join' those extra tables into the result set that you're binding to or use the Navigation properties of your L2S generated classes and shape the returning data.

您需要将这些额外的表“连接”到您要绑定的结果集中,或者使用L2S生成的类的导航属性并对返回的数据进行整形。

Something like this:

像这样的东西:

var results = (from r in <yourSource> select new 
{
    Name = r.Name,
    FormName = r.FormReserves.Forms.FormName,
    Number = r.FormReserves.Number
});

#1


1  

You need to either 'join' those extra tables into the result set that you're binding to or use the Navigation properties of your L2S generated classes and shape the returning data.

您需要将这些额外的表“连接”到您要绑定的结果集中,或者使用L2S生成的类的导航属性并对返回的数据进行整形。

Something like this:

像这样的东西:

var results = (from r in <yourSource> select new 
{
    Name = r.Name,
    FormName = r.FormReserves.Forms.FormName,
    Number = r.FormReserves.Number
});