我使用<SharePoint:SPCalendarView id=spcalView runat="server"> </SharePoint:SPCalendarView>
创建了自定义日历。
然后我在日历列表中插入了一些事件,我可以在上面创建的视图spcalView中显示事件。为此,我将SPListItemCollection
(即从日历列表中检索到的集合)传递给函数MakeSchedule()
。
private SPCalendarItemCollection MakeSchedule(SPListItemCollection calListItems)
{
SPCalendarItemCollection items = new SPCalendarItemCollection();
for (int i = 0; i < calListItems.Count; i++)
{
SPListItem item = calListItems[i];
DateTime StartTime = Convert.ToDateTime(item["EventDate"]);
DateTime EndTime = Convert.ToDateTime(item["EndDate"]);
string appointmentId = "";
if (item["AppointmentID"] != null)
appointmentId = item["AppointmentID"].ToString();
string clientID = "";
if (item["clientID"] != null)
clientID = item["clientID"].ToString();
string Description = "";
if (item["Description"] != null)
Description = item["Description"].ToString();
string Location = "";
if (item["Location"] != null)
Location = item["Location"].ToString();
string Title = "";
if (item["Title"] != null)
Title = item["Title"].ToString();
bool Recurrance = false;
if (item["fRecurrence"] != null)
Recurrance = (bool)item["fRecurrence"];
bool AllDayEvent = false;
if (item["fAllDayEvent"] != null)
AllDayEvent = (bool)item["fAllDayEvent"];
SPWeb web = SPContext.Current.Web;
string relativeURL = web.ServerRelativeUrl;
string absoluteURL = web.Url;
items.Add(
new SPCalendarItem()
{
ItemID = item["ID"].ToString(),
StartDate = StartTime,
EndDate = EndTime,
hasEndDate = true,
Title = Title,
Location = Location,
Description = Description,
IsAllDayEvent = AllDayEvent,
IsRecurrence = Recurrance,
CalendarType = (int)SPCalendarType.Gregorian,
BackgroundColorClassName="ApptCnfirmed",
DisplayFormUrl = relativeURL + "/_layouts/TestProj.Webparts/AppointmentsEdit.aspx"
}
);
}
return items;
}
这里针对添加到SPCalendarItemCollection的每个事件项,我已将DisplayFormUrl设置为应用程序页面。因此,当我在Spcalendar视图中单击一个事件时,它会被重定向到应用程序页面以及单击作为查询字符串的项目的ID。
在“应用程序”页面中,检索了ID,并根据ID检索了currentLstItem。但是从那以后我无法在CalendarList中获取我添加的自定义字段。
public partial class AppointmentsEdit : LayoutsPageBase
{
protected void Page_Load(object sender, EventArgs e)
{
string ID = Page.Request.QueryString["ID"].ToString();//this Id is the unique id of the Appointment List
string Source=Page.Request.QueryString["Source"].ToString();
if (ID != "" && ID != null)
{
SPList lstApp = SPContext.Current.Web.Lists["Appointment"];
SPListItem currentLstItem = lstApp.GetItemById(Convert.ToInt32(ID.ToString()));
}
else
{
}
}
}
这是编辑日历事件的正确方法吗?因为我将自定义字段添加到sharepoint中的日历列表中。我尝试使用设计器,但我无法获得EditForm.aspx的代码。
提前致谢!!