【发布时间】:2012-02-28 06:11:42
【问题描述】:
我有一个要求,我必须根据开始日期和结束日期删除下拉项目。 我已经用谷歌搜索了足够多的方法并尝试了许多简单的方法,例如我可以在下拉列表中删除选定的项目。 这里的问题是,它会引发错误,即输入字符串的格式不正确以及如何从下拉列表中跟踪和删除该项目。 请注意,下拉值是从日历列表开始绑定的,并且已在自定义列表中显示为下拉列表(希望清楚)。
下面是我的代码:
protected void BtnRegister_Click(object sender, EventArgs e)
{
try
{
SPSite oSPSiteCollection = SPContext.Current.Site;
SPWeb oSPWeb = SPContext.Current.Web;
SPList oSPList = oSPWeb.Lists["Registered"];
SPListItemCollection oSPListItemCollection = oSPList.Items;
SPListItem oSPListItem = oSPListItemCollection.Add();
DataTable oDataTable = new DataTable();
oSPListItem["Employee Name"] = oSPWeb.CurrentUser.Email.ToString();
string[] UsersSeperated = peopleEditorManager.CommaSeparatedAccounts.Split(',');
SPFieldUserValueCollection UserCollection = new SPFieldUserValueCollection();
SPFieldUserValue UserName = new SPFieldUserValue();
foreach (string UserSeperated in UsersSeperated)
{
oSPWeb.EnsureUser(UserSeperated);
SPUser User = oSPWeb.SiteUsers[UserSeperated];
UserName = new SPFieldUserValue(oSPWeb, User.ID, User.LoginName);
UserCollection.Add(UserName);
}
oSPListItem["peopleEditorManager"] = UserCollection;
oSPListItem["Practice Name"] = TxtPracticeName.Text;
oSPListItem["Course Name"] = ddlDrop.SelectedItem;
oSPListItem["Prerequisite"] = TxtPrerequisite1.Text;
oSPListItem["Beg Date"] = TxtStartDate.Text;
oSPListItem["Finish Date"] = TxtEndDate.Text;
string registeredCourse = oSPListItem["Course Name"].ToString();
SPList oSPListCourse = oSPWeb.Lists["Scheduled Courses"];
SPListItemCollection oSPListItemCollectionCourse = oSPListCourse.Items;
foreach (SPListItem oSPListItemCourse in oSPListItemCollectionCourse)
{
string begginingDate = oSPListItemCourse["Start Date"].ToString();
string finishDate = oSPListItemCourse["End Date"].ToString();
//input string not in correct format
if (( Convert.ToInt32(begginingDate) >= Convert.ToInt32(TxtStartDate.Text) )
|| (Convert.ToInt32(finishDate) <= Convert.ToInt32(TxtEndDate.Text)))
{
//how to remove the item from drop down if their date is greater than StartDate and less than EndDate
ddlDrop.Items.Remove(ddlDrop.SelectedItem);
}
}
oSPListItem.Update();
LblMessage.Text = "Registeres";
String fromID = oSPWeb.CurrentUser.Email.ToString();
String mailTo = UserName.User.Email.ToString();
string titleName = ddlDrop.SelectedItem.ToString();
SendEmail_WU(fromID, mailTo, titleName);
}
catch (Exception ex)
{
LblMessage.Text = ex.Message;
}
}
请帮忙。谢谢。
【问题讨论】:
标签: list sharepoint-2010 drop-down-menu