[問題] asp.net c# repeater取出List資料

看板C_Sharp (C#)作者 (沒有名字的怪物)時間7年前 (2017/12/08 22:59), 編輯推噓1(102)
留言3則, 3人參與, 8年前最新討論串1/1
晚安 想請教一下,我有個Class其結構如下 public class TotalMoneyClass { public List<string> DateStrList = new List<string>(); public List<int> CheckMoneyList = new List<int>(); public string storeName { get; set; } }; 然後我用個List<TotalMoneyClass>去存資料 foreach(string nameStr in mStore){ TotalMoneyClass tmp = new TotalMoneyClass(); tmp.storeName = nameStr; for (int month = 1; month < 13; month++) { //若沒有資料,就當作0 tmp.CheckMoneyList.Add(result.Where(i => i.mStoreName.CompareTo(nameStr) == 0 && i.shop_date.Month == month && i.shop_date.Year == 2017) .Sum(t =>(int?) t.totalSale_money)??0); } listStore.Add(tmp); } Repeater1.DataSource = listStore; Repeater1.DataBind(); 而我想要用Repeater去呈現出TotalMoneyClass裡的List<int> CheckMoneyList 那該怎麼改寫呢?? <asp:Repeater ID="Repeater1" runat="server" OnItemDataBound="Repeater1_ItemDataBound" > <HeaderTemplate> <table> <tr> <th>Name</th> <th>Description</th> </tr> </HeaderTemplate> <ItemTemplate> <tr> <td><%# ((TotalMoneyClass)Container.DataItem).storeName %></td> <td><%# ((TotalMoneyClass)Container.DataItem).CheckMoneyList %></td> </tr> </ItemTemplate> </asp:Repeater> 謝謝 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 1.174.243.17 ※ 文章網址: https://www.ptt.cc/bbs/C_Sharp/M.1512745166.A.315.html

12/09 14:22, 7年前 , 1F
你是要迴圈印出CheckMoneyList變成每一欄td嗎
12/09 14:22, 1F

12/09 18:05, 7年前 , 2F
是的,可以用repeater嗎??
12/09 18:05, 2F

01/04 16:14, 8年前 , 3F
repeater不熟...我都用Razor Page...XD
01/04 16:14, 3F
文章代碼(AID): #1QAgZECL (C_Sharp)
文章代碼(AID): #1QAgZECL (C_Sharp)