Portal Engine
Version 3.x > Portal Engine > CMSCalendar SelectedDate or TodaysDate View modes: 
User avatar
Member
Member
docon - 11/4/2008 1:38:02 PM
   
CMSCalendar SelectedDate or TodaysDate
Hello,
I have cloned the Event Calendar webpart and I am modifying. I am adding to it a cms.repeater underneath the calendar control that lists the events during the displayed month:

DateTime BeginDt = new DateTime(this.calItems.TodaysDate.Year,this.calItems.TodaysDate.Month,1 );

DateTime EndDt = BeginDt.AddMonths(1);

this.repEvtList.WhereCondition = "EventDate between '"+ BeginDt.Date.ToString() +"' and '"+ EndDt.Date.ToString() +"'";

This works on initial Page Load, but not on Postback when clicking the Prev or Next links on the Calendar. Is there a way to get what date the CMSCalendar is currently displaying?

User avatar
Member
Member
docon - 11/4/2008 3:33:24 PM
   
RE:CMSCalendar SelectedDate or TodaysDate
Just got a solution from Kentico Support team via email, Thanks!
The solution is below:

In .ascx:
<div class="Calendar">
<cms:CMSCalendar ID="calItems" runat="server" OnVisibleMonthChanged="calItems_VisibleMonthChanged">
</cms:CMSCalendar>
<asp:Literal ID="evtListHeading" runat="server"></asp:Literal>
<cms:CMSRepeater ID="repEvtList" runat="server">
</cms:CMSRepeater>
</div>

In ascx.cs:
protected void calItems_VisibleMonthChanged(object sender, MonthChangedEventArgs e)
{
this.evtListHeading.Text = "<div class=\"EvtListHeading\">" + e.NewDate.ToString("MMMM yyyy") + " Events</div>";

DateTime BeginDt = new DateTime(e.NewDate.Year, e.NewDate.Month, 1);
DateTime EndDt = BeginDt.AddMonths(1);

this.repEvtList.WhereCondition = "EventDate between '" + BeginDt.Date.ToString() + "' and '" + EndDt.Date.ToString() + "'";
this.repEvtList.ReloadData(true);

}