我有以下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或一個月曆歷選擇但它retunr對象,所以我可以給的ItemDataBound DataItem的? 任何幫助都會大大降低。
哪些數據項你會期望嗎?每組只有任意一個? – BrokenGlass 2012-03-09 16:31:50
因此,如果兩個遊覽有相同的月份,你想使用哪一個? – AakashM 2012-03-09 16:33:00