protected override void CreateChildControls() { base.CreateChildControls(); try { SPWeb web = SPContext.Current.Web; spCalendarHolidayView = new SPCalendarView(); spCalendarHolidayView.EnableViewState = true; spCalendarHolidayView.EnableV4Rendering = web.UIVersion >= 4; spCalendarHolidayView.NewItemFormUrl = web.ServerRelativeUrl.TrimEnd('/') + Constants.Pages.HOLIDAY_FORM_PAGE_URL + "?Mode=3"; spCalendarHolidayView.EditItemFormUrl = web.ServerRelativeUrl.TrimEnd('/') + Constants.Pages.HOLIDAY_FORM_PAGE_URL + "?Mode=2"; spCalendarHolidayView.DisplayItemFormUrl = web.ServerRelativeUrl.TrimEnd('/') + Constants.Pages.HOLIDAY_FORM_PAGE_URL + "?Mode=1"; string viewType = this.CalendarPeriod; string selectedDate = SPUtility.GetSelectedDate(Request, web); Tuple <DateTime, DateTime> calendarPeriod = Utils.GetCalendarViewPeriod(SPContext.Current.Web.GetDateOptions(Request), viewType); spCalendarHolidayView.ViewType = viewType; spCalendarHolidayView.SelectedDate = selectedDate; // Bind the datasource to the SPCalendarView var ds = new SPCalendarItemCollection(); short calendarType = web.RegionalSettings.CalendarType; var holidays = new RosterDataService().ListHolidayEvents().OrderBy(item => item.HolidayDate).ToList(); ds.AddRange(holidays.Select(item => new SPCalendarItem() { DisplayFormUrl = web.ServerRelativeUrl.TrimEnd('/') + Constants.Pages.HOLIDAY_FORM_PAGE_URL + "?Mode=1", CalendarType = calendarType, ItemID = item.Id.ToString(), StartDate = item.HolidayDate.Date, EndDate = item.HolidayDate.Date.AddSeconds(86400), hasEndDate = true, Title = item.Holiday.Name, Location = item.Holiday.HolidayType.Name, IsAllDayEvent = true, IsRecurrence = false }).ToList()); // data bind spCalendarHolidayView.DataSource = ds; spCalendarHolidayView.DataBind(); // add Calendar to page this.Controls.Add(spCalendarHolidayView); } catch (Exception ex) { Controls.Add(new Label() { Text = ex.Message, ForeColor = System.Drawing.Color.Red }); Controls.Add(new Label() { Text = " StackTrace: " + ex.StackTrace, ForeColor = System.Drawing.Color.Red }); } }
/// <summary> /// Called by the ASP.NET page framework to notify server controls /// that use composition-based implementation to create any child /// controls they contain in preparation for posting back or rendering. /// </summary> protected override void CreateChildControls() { _calendarView = new SPCalendarView { Width = new Unit(100, UnitType.Percentage) }; _xmlCalendar = GetCalendarXML(); if (_xmlCalendar != null) { _xmlCalendar.Decorate(_calendarView); } if (Page.Request.QueryString["CalendarPeriod"] != null) { const string month = "month"; const string day = "day"; const string week = "week"; const string timeline = "timeline"; switch (Page.Request.QueryString["CalendarPeriod"].ToLower()) { case month: _calendarView.ViewType = month; break; case day: _calendarView.ViewType = day; break; case week: _calendarView.ViewType = week; break; case timeline: _calendarView.ViewType = timeline; break; } } _calendarView.EnableViewState = true; Controls.Add(_calendarView); base.CreateChildControls(); }
/// <summary> /// Fills the specified calendar view. /// </summary> /// <param name="calendarView">The calendar view.</param> public void Fill(SPCalendarView calendarView) { calendarView.DataSource = DataSource(); }
/// <summary> /// Decorates the specified calendar view. /// </summary> /// <param name="calendarView">The calendar view.</param> public void Decorate(SPCalendarView calendarView) { //calendarView.SelectedDate = DateTime.Now.ToString(); calendarView.ViewType = ViewType; }