简体   繁体   English

GridView C#中的垂直列

[英]vertical columns in a gridview c#

I want vertical columns in my gridview I google it but ain't get anything in return, 我希望在gridview垂直列进行搜索,但不会得到任何回报,

rows in my gridview consist of only one record that is why i want to show my gridview columns vertically gridview行仅包含一条记录,这就是为什么我想vertically显示我的gridview columns

anyone knows the easy way (if possible) for how to show vertical columns in a gridview ? 有谁知道如何在gridview显示vertical columns的简单方法(if possible)

Assume this is the structure of your table: 假设这是表的结构:

CREATE TABLE EmpInfo(
    Id INT NOT NULL,
    Name VARCHAR(200) NOT NULL,
    Salary Decimal(18,8) NOT NULL
)

You need to unpivot the row to show information to convert Row to Columns : 您需要unpivot行以显示信息,以将Row转换为Columns

SELECT * FROM
(
    SELECT  CAST(Id as VARCHAR(200)) [Id], Name, CAST(Salary as VARCHAR(200)) [Salary]
    FROM    EmpInfo
) e
UNPIVOT
(
    Val FOR Col IN ([Id], [Name], [Salary])
) x

You need cast, as we need same data type for all values we are pivoting on. 您需要强制转换,因为我们需要对所有数据值使用相同的数据类型。

Hope you can take it from here. 希望你可以从这里拿走。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM