Click here to Skip to main content
15,905,785 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted

1 solution

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

SQL
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
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900