I have the following
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");
}
}
}
Is there a way i can GroupBy or Distinctly select by month but have it retunr the object so i can get to the itemdatabound dataitem?
Any help would be greatly apreciated.
First do the
GroupByto get anIEnumerable<IGrouping<int, Excursion>>where theintisExcursion.StartDate.Month:Change the method below:
UPDATE: Added the OrderBy