• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 701
  • Last Modified:

convert a datatable or list<objects> into gridview

I have a datatable with 3 fields state, carrier and rate. I have to display it in a gridview such that y-axis will be state and x-axis will be carrier and the corresponding cell display the rate.
datatable structure
state carrier rate
NB     hunt   1.0
NB     atl       .23
NX     hunt   2.5
NX     atl       .45

gridview should be
         hunt   atl
NB    1.0     .23
NX    2.5     .45
0
Niyas
Asked:
Niyas
2 Solutions
 
Asim NazirCommented:
You need to convert rows into column. You can do using Pivot. Details here:
http://msdn.microsoft.com/en-us/library/ms177410.aspx
0
 
Pratima PharandeCommented:
You can pivote the datatable and create new datatable as per your requiremnt

refer the below link
which provides step by step details of how to do it and assign to grid

http://aspalliance.com/538_CodeSnip_Pivot_Tables_with_ADONET_and_Display_in_a_DataGrid_Paged_Horizontally.all
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now