Asked by:
Gridview/Listview

Question
-
User-1499457942 posted
Hi
How to create Gridview/Listview like below
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
Saturday, June 30, 2018 11:44 AM
All replies
-
User475983607 posted
Hi
How to create Gridview/Listview like below
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.
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
Saturday, June 30, 2018 11:52 AM -
User-330142929 posted
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.
<div> <asp:GridView ID="GridView1" runat="server" GridLines="None"></asp:GridView> </div>
Code behind.
protected void Page_Load(object sender, EventArgs e) { DataTable dt = new DataTable(); dt.Columns.AddRange(new DataColumn[] { new DataColumn("ID"), new DataColumn("Name"),new DataColumn("Price") }); dt.Rows.Add(1, "Apple",12); dt.Rows.Add(2, "Grape",32); this.GridView1.DataSource = dt; this.GridView1.DataBind(); }
Feel free to let me know if you have any question.
Best Regards.
Abraham
Monday, July 2, 2018 9:42 AM -
User-1034726716 posted
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
Tuesday, July 3, 2018 1:05 AM -
User1108898723 posted
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.
Wednesday, July 18, 2018 6:48 AM