我試圖從列表框中刪除特定的項目,但是我收到了轉換錯誤。 它似乎不喜歡我已經將ListBox中的項目稱爲string
項目的事實。無法將ListItem類型的對象轉換爲字符串
if (CheckBox1.Checked == true)
{
foreach (string item in ListBox1.Items)
{
WebService1 ws = new WebService1();
int flag = ws.callFlags(10, item);
if (flag == 1)
{
ListBox1.Items.Remove(item);
}
}
}
錯誤 -
Unable to cast object of type 'System.Web.UI.WebControls.ListItem' to type 'System.String'.
我怎樣才能解決這個問題?
編輯
我的問題是,當我更改爲(ListItem item in ListBox1.Items)
方法(我試過)行 - int flag = ws.callFlags(10, item);
符,因爲Web服務正在接收string
明確。這就給出了錯誤 -
Error 2 Argument 2: cannot convert from 'System.Web.UI.WebControls.ListItem' to 'string'
Error 1 The best overloaded method match for 'testFrontEnd.WebService1.callFlags(int, string)' has some invalid arguments
使用'ListItem'而不是'string'。 –
請參閱編輯,因爲我已經試圖實現這一點,問題是Web服務需要一個字符串。 – Ebikeneser