私はC#lambda、月のみの.Distinct()またはGroupBy()を選択しますか?
protected void Page_Load(object sender, EventArgs e)
{
DataX dx = new DataX();
List<Excursion> lstExcur = new List<Excursion>();
lstExcur = dx.GetAllExcursions();
rptExcursionOuter.DataSource = lstExcur.Distinct(x => x.StartDate.Month);
rptExcursionOuter.DataBind();
}
protected void rptExcursionOuter_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
if (e.Item.DataItem != null)
{
Excursion Ritem = (Excursion)e.Item.DataItem;//<---- this bit errors, is there a way to keep the object intact but group or distinct by month?
Literal LitExcursionMonth = (Literal)e.Item.FindControl("LitExcursionMonth");
LitExcursionMonth.Text = Ritem.StartDate.ToString("MMMM");
}
}
}
は私ができるGROUPBYかはっきりと選択方法は月ごとにありますが、私はitemdataboundデータ項目に得ることができるので、それは、オブジェクトをretunr持って、次がありますか? どんな助けでも大いに評価されるでしょう。
を追加しましたあなたは期待していますか?グループごとに任意の任意の1つ? – BrokenGlass
2回のエクスカーションで同じ月がある場合、どちらを使いたいですか? – AakashM