Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/41.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何将c#列表转换为Jquery电子日历事件?_Javascript_C#_Jquery_Asp.net_Sharepoint - Fatal编程技术网

Javascript 如何将c#列表转换为Jquery电子日历事件?

Javascript 如何将c#列表转换为Jquery电子日历事件?,javascript,c#,jquery,asp.net,sharepoint,Javascript,C#,Jquery,Asp.net,Sharepoint,我在前端有一个jquery事件日历(e-calendar)并从SharePoint日历(c#)检索事件,如何将此c#代码转换为显示在jquery e-calendar事件中 Jquery事件日历: C#代码: 受保护的无效页面加载(对象发送方,事件参数e) { 如果(!IsPostBack) { SPListItemCollection corporateCalendarListItems=GetCorporateCalendarItems(); 如果(corporateCalendarLis

我在前端有一个jquery事件日历(e-calendar)并从SharePoint日历(c#)检索事件,如何将此c#代码转换为显示在jquery e-calendar事件中

Jquery事件日历:

C#代码:

受保护的无效页面加载(对象发送方,事件参数e)
{
如果(!IsPostBack)
{
SPListItemCollection corporateCalendarListItems=GetCorporateCalendarItems();
如果(corporateCalendarListItems!=null){AddCorporateCalendarEventsToUI(corporateCalendarListItems);}
}
}
私有SPListItemCollection GetCorporateCalendarItems()
{
使用(SPSite wadiSite=SPContext.Current.Site)
{
使用(SPWeb wadiWeb=wadiSite.OpenWeb())
{
wadiWeb.AllowUnsafeUpdates=true;
//取名单
SPList corporateCalendarList=wadiWeb.Lists.TryGetList(“公司日历”);
//返回最后一项
如果(corporateCalendarList!=null)
{
DateTime todayDate=DateTime.Now;
字符串月份=todayDate.ToString(“MM”);
字符串year=todayDate.ToString(“yyy”);
字符串endOfMonthDate=年+“-”+月+“-30”;
字符串startOfMonthDate=year+“-”+month+“-01”;
SPQuery qry=new SPQuery();
qry.Query=@“假日”+startOfMonthDate+“”+endOfMonthDate+“T12:00:00Z”;
qry.ViewFields=@”;
SPListItemCollection corporateCalendarListItems=corporateCalendarList.GetItems(qry);
返回corporateCalendarListItems;
}
返回null;
}
}
}
私有void AddCorporateCalendarEventsToUI(SPListItemCollection corporateCalendarListItems)
{
List calendarEvents=新列表();
foreach(corporateCalendarListItems中的SPListItem corporateCalendarListItems)
{
CalendarEvent CalendarEvent=新CalendarEvent();
calendarEvent.Title=corporateCalendarListItem[“Title”].ToString();
如果(corporateCalendarListItem[“EventDate”]!=null)
{
calendarEvent.StartDate=DateTime.Parse(corporateCalendarListItem[“EventDate”].ToString());
}
如果(corporateCalendarListItem[“EndDate”]!=null)
{
calendarEvent.EndDate=DateTime.Parse(corporateCalendarListItem[“EndDate”].ToString());
}
calendarEvent.Category=“Test”;
calendarEvent.AllDay=false;
calendarEvents.Add(calendarEvent);
}
}

你能帮我写一些代码吗?代码:private void AddEventsToUI(SPListItemCollection calendarItems){List calendarEvents=new List();foreach(calendarItem中的SPListItem calendarItem){CalendarEvent CalendarEvent=new CalendarEvent();CalendarEvent.Title=calendarItem[“Title”].ToString();calendarEvent.StartDate=DateTime.Parse(calendarItem[“EventDate”].ToString());calendarEvent.EndDate=DateTime.Parse(calendarItem[“EndDate”].ToString());calendarEvents.Add(calendarEvent);}}}Jquery事件日历:将代码从评论部分移动并添加到您的帖子中(您提出问题的地方).完成向帖子添加代码
protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            SPListItemCollection corporateCalendarListItems = GetCorporateCalendarItems();
            if (corporateCalendarListItems != null) { AddCorporateCalendarEventsToUI(corporateCalendarListItems); }
        }
    }

    private SPListItemCollection GetCorporateCalendarItems()
    {
        using (SPSite wadiSite = SPContext.Current.Site)
        {
            using (SPWeb wadiWeb = wadiSite.OpenWeb())
            {
                wadiWeb.AllowUnsafeUpdates = true;

                // Fetch the List
                SPList corporateCalendarList = wadiWeb.Lists.TryGetList("Corporate Calendar");

                // Return the last item
                if (corporateCalendarList != null)
                {
                    DateTime todayDate = DateTime.Now;
                    string month = todayDate.ToString("MM");
                    string year = todayDate.ToString("yyyy");
                    string endOfMonthDate = year + "-" + month + "-30";
                    string startOfMonthDate = year + "-" + month + "-01";
                    SPQuery qry = new SPQuery();
                    qry.Query = @"<Where><And><And><Eq><FieldRef Name='Category'  /><Value Type='Choice'>Holiday</Value></Eq><Geq><FieldRef Name='EventDate' /><Value Type='DateTime'>"+startOfMonthDate+"</Value></Geq></And><Leq><FieldRef Name='EventDate' /><Value Type='DateTime'>" + endOfMonthDate + "T12:00:00Z</Value></Leq></And></Where><OrderBy><FieldRef Name='EventDate' /></OrderBy>";
                    qry.ViewFields = @"<FieldRef Name='Title' /><FieldRef Name='EventDate' /><FieldRef Name='FileRef' /><FieldRef Name='EndDate' /><FieldRef Name='Category' />";
                    SPListItemCollection corporateCalendarListItems = corporateCalendarList.GetItems(qry);

                    return corporateCalendarListItems;
                }
                return null;
            }
        }
    }

    private void AddCorporateCalendarEventsToUI(SPListItemCollection corporateCalendarListItems)
    {
        List<CalendarEvent> calendarEvents = new List<CalendarEvent>();

        foreach (SPListItem corporateCalendarListItem in corporateCalendarListItems)
        {
            CalendarEvent calendarEvent = new CalendarEvent();
            calendarEvent.Title = corporateCalendarListItem["Title"].ToString();

            if(corporateCalendarListItem["EventDate"] != null)
            {
                calendarEvent.StartDate = DateTime.Parse(corporateCalendarListItem["EventDate"].ToString());
            }
            if (corporateCalendarListItem["EndDate"] != null)
            {
                calendarEvent.EndDate = DateTime.Parse(corporateCalendarListItem["EndDate"].ToString());
            }
            calendarEvent.Category = "Test";
            calendarEvent.AllDay = false;

            calendarEvents.Add(calendarEvent);
        }
    }