1
var TatalFeeCollectionDetail = new List<lcclsTotalFeeCollectionDetail>();
TatalFeeCollectionDetail = (from t in .......
                            group t by new { t.MonthName,t.FeeParticularName }                                        
                                into grp                                           
                                select new lcclsTotalFeeCollectionDetail                                           
                                {
                                    Month = grp.Key.MonthName,
                                    Particular = grp.First().FeeParticularLedgerName,
                                    Amount = grp.Sum(t => t.Amount),
                                }).ToList();
dgvTotalFeeCollectionDetail.DataSource = TatalFeeCollectionDetail;

My result is this .............

    Month   particular Amount   
    April       b      1    
    April       c      2    
    April       d      1    
    April       e      2
    April       f      1

I want to convert it like this can any1 help me...........I search for it but can,t understood what to do....

Month   b   c   d   e   f   Total Amount
April   1   2   1   2   1       7

Thanxxxxxxx in advance

Coderz
  • 245
  • 6
  • 20

2 Answers2

2

You can't. That would mean creating an anonymous type with a variable number of properties, and it's not possible in C# which is strongly typed.

What you can certainly do is storing the 'particular' values in a Dictionary and get a result like

Month     particular                                  Total
April     {{b, 1}, {c, 2}, {d, 1}, {e, 2}, {f, 1}}    7
Stephane Delcroix
  • 16,134
  • 5
  • 57
  • 85
0

Nearly nine years after asking: You Could try a GroupJoin in a GroupBy

string[] particulars = TatalFeeCollectionDetail.Select(x => x.FeeParticularName ).Distinct().ToArray();
var crossTabbedData=TatalFeeCollectionDetail.GroupBy(TFCD => TFCD.Month).Select(TFCD => new {Month=TFCD.Key,RowData=particulars.GroupJoin(TFCD, p => p, t => t.FeeParticularName, (p, t) => t.Count() == 0 ? 0 : t.Sum(fn => fn.Amount)).ToList()}).ToList();

Should produce something like what you want, but perhaps without column headers.

Mikey
  • 11
  • 3