List 输入字符串格式不正确,请从下拉列表中删除下拉列表项
我需要根据开始日期和结束日期删除下拉项。 我已经在谷歌上搜索了足够多的内容,并尝试了许多简单的方法,比如我可以在下拉列表中删除选中的项目。 这里的问题是,输入字符串的格式不正确以及如何跟踪并从下拉列表中删除该项会引发错误。 请注意,下拉列表值是从日历列表开始绑定的,它已在自定义列表中显示为下拉列表(希望清楚) 以下是我的代码:List 输入字符串格式不正确,请从下拉列表中删除下拉列表项,list,sharepoint-2010,drop-down-menu,List,Sharepoint 2010,Drop Down Menu,我需要根据开始日期和结束日期删除下拉项。 我已经在谷歌上搜索了足够多的内容,并尝试了许多简单的方法,比如我可以在下拉列表中删除选中的项目。 这里的问题是,输入字符串的格式不正确以及如何跟踪并从下拉列表中删除该项会引发错误。 请注意,下拉列表值是从日历列表开始绑定的,它已在自定义列表中显示为下拉列表(希望清楚) 以下是我的代码: protected void BtnRegister_Click(object sender, EventArgs e) { try {
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;
}
}
protectedvoid BtnRegister\u单击(对象发送者,事件参数e)
{
尝试
{
SPSite oSPSiteCollection=SPContext.Current.Site;
SPWeb-oSPWeb=SPContext.Current.Web;
SPList-oSPList=oSPWeb.Lists[“已注册”];
SPListItemCollection=oSPList.Items;
SPListItem oSPListItem=oSPListItemCollection.Add();
DataTable oDataTable=新DataTable();
oSPListItem[“员工姓名”]=oSPWeb.CurrentUser.Email.ToString();
string[]UsersOperated=peopleEditorManager.CommaSeparatedAccounts.Split(',');
SPFieldUserValueCollection UserCollection=新建SPFieldUserValueCollection();
SPFieldUserValue用户名=新的SPFieldUserValue();
foreach(字符串userseparated in users操作)
{
oSPWeb.EnsureUser(用户分离);
SPUser User=oSPWeb.SiteUsers[userseparated];
用户名=新的SPFieldUserValue(oSPWeb、User.ID、User.LoginName);
UserCollection.Add(用户名);
}
oSPListItem[“peopleEditorManager”]=用户集合;
oSPListItem[“机构名称”]=TxtPracticeName.Text;
oSPListItem[“课程名称”]=ddlDrop.SelectedItem;
oSPListItem[“先决条件”]=TxtPrerequisite1.Text;
oSPListItem[“Beg Date”]=TxtStartDate.Text;
oSPListItem[“完成日期”]=TxtEndDate.Text;
string registeredCourse=oSPListItem[“课程名称”]。ToString();
SPList-oSPListCourse=oSPWeb.list[“预定课程”];
SPListItemCollection oSPListItemCollectionCourse=oSPListCourse.Items;
foreach(oSPListItemCollectionCourse中的SPListItem oSPListItemCourse)
{
字符串begginingDate=oSPListItemCourse[“开始日期”]。ToString();
字符串finishDate=oSPListItemCourse[“结束日期”]。ToString();
//输入字符串格式不正确
if((Convert.ToInt32(begginingDate)>=Convert.ToInt32(TxtStartDate.Text))
||(根据您的评论将.Convert.ToInt32(finishDate):
如果项目的日期大于StartDate且小于EndDate,如何从下拉列表中删除该项目
听起来您应该使用或而不是Convert.ToInt32
此外,您的注释是“和”,但代码中的|
是“或”。您的病情的左右两侧需要翻转
以下代码应该实现您的注释所表达的内容:
//input string not in correct format
if ((Convert.ToDateTime(TxtStartDate.Text) > Convert.ToDateTime(begginingDate))
&& (Convert.ToDateTime(TxtEndDate.Text) < Convert.ToDateTime(finishDate)))
{
// how to remove the item from drop down if their date is
// greater than StartDate and less than EndDate
ddlDrop.Items.Remove(ddlDrop.SelectedItem);
}
//输入字符串格式不正确
if((Convert.ToDateTime(TxtStartDate.Text)>Convert.ToDateTime(begginingDate))
&&(Convert.ToDateTime(TxtEndDate.Text)
如果这不能满足您的需求,那么您需要重新审视您的需求