0

I am new to ASP.NET. the problem is i have a View in database like this

number   TVchannel       Spots
101      channel1        5
102      channel2        7
103      channel3        3

what data component in asp.net shows that view into a different way, like this for example

number    channel1     channel2    channel3
101       5            7           3

That was easy in script case but i cant find a component or a way to do it in .net. I am using framework 4.0.

Can GridView do this?

Cœur
  • 37,241
  • 25
  • 195
  • 267
user3189504
  • 161
  • 1
  • 1
  • 12

1 Answers1

0

I'm a bit confused with your data example. I don't understand why you want to display values:

number     channel1     channel2      channel3
101        5            7            3

when spots 7 and 3 are not related to number 101. I assumed that there should be only 101 values in original data you supplied. So...

What you need is Pivot Table. This is quite complicated complicated component and there is no such component in basic ASP.Net WebForms. There are two solutions.

You can try pivoting data on database side (example in T-SQL):

SELECT number, [channel1] AS 'channel1',[channel2] AS 'channel2',[channel3] AS 'channel3'
FROM
(
SELECT number,TVchannel,Spots FROM YourView
) AS src
PIVOT
(
    MAX(Spots)
    FOR TVchannel IN ([channel1],[channel2],[channel3])
) AS piv

Alternatively you can try some dedicated component. That is what I found after quick googling: StackOverflow solution to similar problem DevExpress component Telerik component

Community
  • 1
  • 1
semao
  • 1,757
  • 12
  • 12