合并两个数据源的GridView? [英] merge two datasource to gridview?

查看:258
本文介绍了合并两个数据源的GridView?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是做的最好的方式?我有一个表,返回数据的一组和另一个表返回另一组数据,所以在我的GridView我想显示

what is the best way of doing?, i have one table that returns one set of data and another table that returns another set of data, so in my gridview i want to display

ID,名称=数据集1
registration_id,registration_name = dataset2

id,name = dataset1 registration_id, registration_name = dataset2

推荐答案

最好的办法是使用的从数据库中选择数据时,JOIN

Best bet is to use a JOIN when selecting the data from the database.

如果这是不可能的,有几种方法在内存DataTable对象来完成这个...

If that's not possible, there are several ways to accomplish this with DataTable objects in memory...

一种可能是这里概述:<一href=\"http://msmvps.com/blogs/shahed/archive/2009/02/09/asp-net-tips-display-resultset-from-multiple-datatable.aspx\" rel=\"nofollow\">http://msmvps.com/blogs/shahed/archive/2009/02/09/asp-net-tips-display-resultset-from-multiple-datatable.aspx这就是我通常做,如果我绝对不能仅仅从我想要的格式服务器获得它直接。

One possibility is outlined here: http://msmvps.com/blogs/shahed/archive/2009/02/09/asp-net-tips-display-resultset-from-multiple-datatable.aspx This is how I usually do it if I absolutely can't just get it directly from the server in the format I want.

您也可以做到这一点使用的LINQ

You can also do it using Linq

与LINQ一个加入一个例子也可以在这里找到:的http:/ /www.vbdotnetheaven.com/Uplo​​adFile/ShahanDev/4601/Default.aspx

An example of a JOIN with LINQ can also be found here: http://www.vbdotnetheaven.com/UploadFile/ShahanDev/4601/Default.aspx

编辑 - 添加了基于注释

,我不知道,在GridView加入结果必然是你想要的。在一个一对多的关系,你会从一方获得duplicaiton。

Based on your comments, I'm not sure that joining the results in a gridview is necessarily what you want. In a one-to-many relationship you will get duplicaiton from the "one" side.

如果我猜对了,你真正想要的是什么,更准确地重新presents一个一对多的关系,而不是这样的,看起来像这样的数据:

If I'm guessing right, what you really want is something that more accurately represents the one-to-many relationship so instead of data that looks like this:

id | name | reg_id | reg_name |
1  |abs   | 1      |adad      |
1  |abs   | 2      |sadsd     |

你真的希望它看起来是这样的:

you really want it to look like this:

1  abs
   1   adad
   2   sadsd

在这种情况下,你就要去寻找到嵌套的中继器更好地: http://support.microsoft。 COM / KB / 306154 或另一种方式来重新present heriarchical数据。

In that case, you're better off looking into Nested Repeaters: http://support.microsoft.com/kb/306154 or another way to represent heriarchical data.

这篇关于合并两个数据源的GridView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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