简体   繁体   中英

vertical columns in a gridview c#

I want vertical columns in my gridview I google it but ain't get anything in return,

rows in my gridview consist of only one record that is why i want to show my gridview columns vertically

anyone knows the easy way (if possible) for how to show vertical columns in a gridview ?

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 :

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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