Ecode Ename Apr-sal May-sal Jun-sal Jul-sal
1 abc 10000 10000 10000 10000
2 def 12000 12000 12000 12000
and so on
Thanks
Start by posting the code that you have written as binding to a GridView or ListView is pretty simple and openly published. That way we can make sure that you are at least making an attempt given your previous posts.
It seems you're asking about how to prepare data for the pivot table (cross-tab) in C#. For this purpose you can try my
NReco PivotData library:
// lets assume this is your input data with columns:
// "Ecode", "Ename", "month", "salary"
DataTable tbl;
var pvtData = new PivotData(
new[] {"Ecode", "Ename", "month" }, // columns for grouping
new SumAggregatorFactory("salary") // measure to calculate
);
pvtData.ProcessData(new DataTableReader(tbl));
var pvtTbl = new PivotTable(
new [] {"Ecode", "Ename"}, //rows
new [] {"month"}, //columns
pvtData);
// now you can use pvtTbl.RowKeys and pvtTbl.ColumnKeys to iterate through pivot table
// and use indexer to access the value and prepare data for binding to ListView
// or you can use 'PivotTableDataTableWriter' class from NReco.PivotData.Extensions nuget package and get pivoted DataTable:
var dataTableWr = new PivotTableDataTableWriter("Test");
var tbl = dataTableWr.Write(pvtTbl);
NReco.PivotData nuget package can be used for free in single-deployment non-SaaS apps; For advanced components from NReco.PivotData.Extensions commercial license is required.
Member
504 Points
1777 Posts
Gridview/Listview
Jun 30, 2018 11:44 AM|JagjitSingh|LINK
Hi
How to create Gridview/Listview like below
Thanks
All-Star
36941 Points
14913 Posts
Re: Gridview/Listview
Jun 30, 2018 11:52 AM|mgebhard|LINK
Start by posting the code that you have written as binding to a GridView or ListView is pretty simple and openly published. That way we can make sure that you are at least making an attempt given your previous posts.
https://msdn.microsoft.com/en-us/library/fkx0cy6d(v=vs.110).aspx
Also it seems like you might be asking a design question. Do you need a pivot query? Can you explain the problem you are trying to solve?
https://docs.microsoft.com/en-us/sql/t-sql/queries/from-using-pivot-and-unpivot?view=sql-server-2017
Member
650 Points
281 Posts
Re: Gridview/Listview
Jul 02, 2018 09:42 AM|Abraham Qian|LINK
Hi JagjitSingh,
According to your description, you want to bind the data to gridview/listview, I have made a demo, wish it is useful to you.
Aspx.
Code behind.
How it works.
Feel free to let me know if you have any question.
Best Regards.
Abraham
All-Star
102883 Points
19464 Posts
MVP
Re: Gridview/Listview
Jul 03, 2018 01:05 AM|vinz|LINK
That's pretty much basic. What exactly you were trying to accomplish? Also, what have you tried?
If you are new on working with ASP.NET GridView, you can download a copy of this eBook: ASP.NET GridView Control Pocket Guide
Microsoft MVP, CodeProject MVP, C# Corner MVP
Blog | Twitter | Linkedin
Member
80 Points
34 Posts
Re: Gridview/Listview
Jul 18, 2018 06:48 AM|VitaliyMF|LINK
It seems you're asking about how to prepare data for the pivot table (cross-tab) in C#. For this purpose you can try my NReco PivotData library:
NReco.PivotData nuget package can be used for free in single-deployment non-SaaS apps; For advanced components from NReco.PivotData.Extensions commercial license is required.