开发者

Displaying multi table values in a single GridView column

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

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

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

Form开发者_运维技巧s
------
ID FormName
33 form name

MainTable.FormReserveId foreign key to FormReserves.ID

FormReserves.FormId foreign key to Forms.ID

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


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.

Something like this:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜