Click here to Skip to main content
15,912,457 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Geeks,

I just stuck up with a logic. Can someone help me to figure out the logic.
The problem is ...

In Gridview,

HTML
Combo        SIZE     RATIO
 1            50        1
 1            56        2
 1            62        1
 2            56        1
 2            62        2
 2            68        2


So there only 2 combos(1,2) and 4 sizes( 50,56,62,68) and I need to show the report like this.
HTML
Combo    50   56   62   68(Depends on gridview addition)
  1      1     2    1    -
  2      -     1    2    2


No duplicates allowed ....

I used List<tuple> and stored all values like key value pair. Is there any logic to find out ???
Posted
Comments
DamithSL 8-Jul-14 5:50am    
how you store data? can you update the question with that code?
Sriram Ramachandran 8-Jul-14 6:02am    
I didnt save the data. Just wanna see the details before saving to the DB. Just displaying whatever typed in Gridview
jo.him1988 8-Jul-14 6:35am    
hi if grid view data is bind from database table than pivot is the answer :)
SELECT * from (select Combo,[Size], ratio FROM PivotTesting)as s
PIVOT(Sum( ratio)FOR [Size] IN([50],[56],[62],[68]))AS test

output
Combo 50 56 62 68
1 1 2 1 null
2 null 1 2 2

happy coding :) :)

1 solution

Yeah you can do this using those key value pairs. But that is not an efficient solution.

I would suggest you to refer the article - Pivoting DataTable Simplified[^] and implement the same.
 
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