本文介绍了SpCalendarView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!

我尝试使用SpCalendarView创建自定义日历,但无法正常工作,我不理解为什么不显示日历项.

I try create custom Calendar with SpCalendarView, but not working and I don't undarstand why not show calendar items.

这是代码:


using System;
using System.ComponentModel;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;

namespace CalendarProject.CalendarWebPArt
{
    [ToolboxItemAttribute(false)]
    public class CalendarWebPArt : WebPart
    {
        SPCalendarItemCollection items = new SPCalendarItemCollection();
        protected override void CreateChildControls()
        {
            base.CreateChildControls();

                AddCalendar();

        }

        private void AddCalendar()
        {

            SPCalendarView calView = new SPCalendarView();
            calView.ViewType = GetCalendarType(Page.Request["CalendarPeriod"]);
            calView.DataSource = GetCalendarItems();
            calView.DataBind();
            Controls.Add(calView);
        }
        private SPCalendarItemCollection GetCalendarItems()

            {
                SPWeb web = SPContext.Current.Site.RootWeb;
                SPList list = web.Lists["Naptár"];

                SPCalendarItemCollection items = new SPCalendarItemCollection();
                foreach (SPListItem Listitem in list.Items)
                {

                    SPCalendarItem item = new SPCalendarItem();

                    string description = "";
                    string location = "";
                    bool recurrence = false;

                    if (Listitem["Description"] != null)
                        description = Listitem["Description"].ToString();
                    if (Listitem["Location"] != null)
                        location = Listitem["Location"].ToString();
                    if (Listitem["fRecurrence"] != null )
                        recurrence = (bool)Listitem["fRecurrence"];

                    item.ItemID = ID.ToString();
                    item.StartDate = (DateTime)Listitem["EventDate"];
                    item.EndDate = (DateTime)Listitem["EndDate"];

                    item.hasEndDate = true;
                    item.Title = Listitem.Title;
                    item.Location = location ;
                    item.Description = description;
                    item.IsAllDayEvent = true;
                    item.IsRecurrence = (bool)Listitem["fRecurrence"];
                    item.IsRecurrence = recurrence;
                    item.CalendarType = Convert.ToInt32(SPCalendarType.Gregorian);

                    items.Add(item);
                }
                return items;
            }
        private static string GetCalendarType(string type)
            {
                if (type == null)
                    type = string.Empty;
                switch (type.ToLower())
                {
                    case "day":
                        return "day";
                    case "week":
                        return "week";
                    case "timeline":
                        return "timeline";
                    default:
                        return "month";
                }
            }


    }
}

推荐答案


这篇关于SpCalendarView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-22 19:24