asp.net - Something not quiet right with my linq statement binding to a listview -
i trying bind grouped linq statement asp.net listview. problem when result been returned list view result this.
system.linq.enumerable+whereenumerableiterator1[transactiondetail] 20.5 system.linq.enumerable+whereenumerableiterator
1[transactiondetail] 7.3
my code nothing special
list<transactiondetail> transactions = new list<transactiondetail>(); transactions.add(new transactiondetail { purchasedate = datetime.now, transactionamount = 2, transactionid = 1, ispurchase = true }); transactions.add(new transactiondetail { purchasedate = datetime.now, transactionamount = 2.2, transactionid = 2, ispurchase = true }); transactions.add(new transactiondetail { purchasedate = datetime.now, transactionamount = 2.9, transactionid = 3, ispurchase = false }); transactions.add(new transactiondetail { purchasedate = datetime.now, transactionamount = 4, transactionid = 4, ispurchase = true }); transactions.add(new transactiondetail { purchasedate = datetime.now, transactionamount = 2.2, transactionid = 5, ispurchase = false }); transactions.add(new transactiondetail { purchasedate = datetime.now, transactionamount = 5, transactionid = 6, ispurchase = true }); transactions.add(new transactiondetail { purchasedate = datetime.now, transactionamount = 5, transactionid = 7, ispurchase = true }); transactions.add(new transactiondetail { purchasedate = datetime.now, transactionamount = 2.3, transactionid = 8, ispurchase = true }); transactions.add(new transactiondetail { purchasedate = datetime.now, transactionamount = 2.2, transactionid = 9, ispurchase = false }); var grouped = t in transactions group t t.ispurchase g select new { addedpurchase = g.where(s=>s.ispurchase), balance = g.sum(s=>s.transactionamount) }; lsttransactions.datasource = grouped; lsttransactions.databind();
my listview looks somthing this
<itemtemplate> <span> <%# eval("addedpurchase")%></span><span> <%# eval("balance")%></span> </itemtemplate>
why seeing system.linq.enumerable+whereenumerableiterator1[webui.transactiondetail] 20.5 returned result. interested in addedpurchase , balance
i cant offer explanation why happening might try following 2 fixes:
add ".tolist()" end of linq query. should stop seeing "whereenumerableiterator1" type description popping up.
add further linq query can select new list of listitems grouping:
lsttransactions.items.addrange( grouped.select(x => new listitem(x.addedpurchase, x.balance) )
edit:
the problem in fact lies second linq query, select out new anonymous type variable grouped:
addedpurchase = g.where(s=>s.ispurchase)
added purchase have value of where() iterator. im not sure purpose of "addedpurchase" variable if example wanted signify purchse had been made, do:
addedpurchase = g.where(s=>s.ispurchase).count() > 0
Comments
Post a Comment