class ModelItem
{
public DateTime EventDate;
public int ScheduledEventId;
public ModelItem(DateTime date, int id)
{
EventDate = date;
ScheduledEventId = id;
}
}
public string GetEventStr()
{
List<ModelItem> Model = new List<ModelItem>();
Model.Add(new ModelItem(new DateTime(2016, 1, 1), 1));
Model.Add(new ModelItem(new DateTime(2016, 1, 2), 2));
Model.Add(new ModelItem(new DateTime(2016, 1, 3), 3));
Model.Add(new ModelItem(new DateTime(2016, 3, 1), 1));
Model.Add(new ModelItem(new DateTime(2016, 3, 2), 2));
StringBuilder sb = new StringBuilder();
int currentMonth = 0;
bool isFirst = true;
foreach (var item in Model)
{
if (item.EventDate.Month != currentMonth)
{
if (isFirst)
isFirst = false;
else
sb.AppendLine("<br />");
sb.AppendLine(item.EventDate.ToString("MMMM") + "<br />");
currentMonth = item.EventDate.Month;
}
sb.AppendLine("Event" + item.ScheduledEventId + "<br />");
}
return sb.ToString();
}