行记录到Gridview列 [英] Rows records to Gridview columns

查看:65
本文介绍了行记录到Gridview列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在表格中有一个记录列表。我想在gridview中动态添加列HeadedText与记录



Ex:

column1

aa

ss

dd



现在我在网格视图中需要这三列

like



aa ss dd

解决方案

您必须更改数据源。 Girdview默认不提供此类功能。所以返回数据的查询必须完成这项工作。你必须使用PIVIOT,它将你的行转换为列。有关详细信息,请访问下面提到的链接



http://msdn.microsoft.com/en-us/library/ms177410(v = sql.105).aspx [ ^ ]



为您的想法,您可以检查示例代码



 选择 
*
来自

选择
PS.Name,P.Color,PIn.Quantity
from Production.Product P
内部 join Production.ProductSubcategory PS
on PS.ProductSubcategoryID = P .ProductSubcategoryID
left join Production.ProductInv entory PIn
on P.ProductID = PIn.ProductID
)DataTable
PIVOT

SUM(数量)
FOR 颜色
IN
[黑], [蓝色],[灰色],[多个],[红色],
[银色],[银色/黑色],[白色],[黄色]

)数据透视表


I have a list of records in a table. I want to add columns inside gridview dynamically HeadedText with the records

Ex:
column1
aa
ss
dd

Now I need these three columns in grid view
like

aa ss dd

解决方案

You have to change you datasource. Girdview does not provide such functionality by default. so the query which returns you the data has to do the job. you have to use PIVIOT which will convert your Rows into Columns. for details please visit the link mentioned below

http://msdn.microsoft.com/en-us/library/ms177410(v=sql.105).aspx[^]

for your idea you can examine the sample code

select
*
from
(
select
PS.Name, P.Color, PIn.Quantity
from Production.Product P
inner join Production.ProductSubcategory PS
on PS.ProductSubcategoryID = P.ProductSubcategoryID
left join Production.ProductInventory PIn
on P.ProductID = PIn.ProductID
) DataTable
PIVOT
(
SUM(Quantity)
FOR Color
IN (
[Black],[Blue],[Grey],[Multi],[Red],
[Silver],[Silver/Black],[White],[Yellow]
)
) PivotTable


这篇关于行记录到Gridview列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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