I am writing a code where I need a GridView to display like as below, what I can do is display columns and its values to fetched from database for the columns but unable to present the data in this format.
My procedure gets one value as Total from DB to be displayed as Amount 1 and do the calculations with that amount to fill in other Amount values and to display the difference between two values as A:B
Any ideas?
--------------------------------------------
Total Amount | | |
--------------------------------------------
Amount 1 | Amount/12 A | |
-------------------------------------------
Amount 2 | Amount/12 B | A:B |
-------------------------------------------
Amount 3 | Amount/12 C | A:C |
-------------------------------------------
Amount ..10 | Amount/12 D | A:D |
-------------------------------------------
Total | | |
--------------------------------------------
Actually I can think of two ways to do this.
Either you go the ugly unintuitive asp.net way and add a handler for the grid’s RowDataBound event. In that handler you would save the a value to a member variable if the member variable is empty. Else if the member variable is unemtpy you would do your calculation and add the difference as a new label in cell 3.
The other way (which I’d like more) you would project your list (be that a datatable or other list) using linq into a new list of anonymous objects which has the properties of the original column plus a computed property for you extra column. Then you may databind the grid to your projected list.