2012-02-28 173 views
0

我有一個要求,我必須刪除下拉項取決於開始日期和結束日期。 這裏的問題是,它會引發輸入字符串格式不正確的錯誤。輸入字符串格式不正確。如何糾正?

foreach (SPListItem oSPListItemCourse in oSPListItemCollectionCourse) 
{ 
string begginingDate = oSPListItemCourse["Start Date"].ToString(); 
string finishDate = oSPListItemCourse["End Date"].ToString(); 
if ((Convert.ToInt32(begginingDate)>=Convert.ToInt32(TxtStartDate.Text)) || (Convert.ToInt32(finishDate)<= Convert.ToInt32(TxtEndDate.Text)))//input string not in correct format 
{ 
ddlDrop.Items.Remove(ddlDrop.SelectedItem);//how to remove the item from drop down if their date is greater than StartDate and less than EndDate 
} 
} 
+0

可能重複的[輸入字符串格式不正確,並從下拉列表中刪除下拉項目](http://stackoverflow.com/questions/9477248/input-string-was-not-in-correct-format-並從下拉列表中刪除項目) – 2012-02-29 14:41:49

回答

0

將開始日期和結束日期值轉換爲日期時間格式而不是字符串。

+0

我的要求是轉換爲字符串:( – missReclusive 2012-02-28 08:29:15

+0

然後爲什麼你檢查條件爲整數值?如果這是要求,然後開始自己轉換爲int。 – Jpaul 2012-02-28 08:34:13

0

您試圖將日期字符串轉換爲整數值。你期望結果如何? 如果您想比較兩個日期,只需將所有值轉換爲DateTime並進行比較即可。