我试图从列表框中删除特定的项目,但是我收到了转换错误。 它似乎不喜欢我已经将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