-5
我给了像'Antony'这样的输入字符串名称。该字符串是列表框项目,并且它也被选中。我怎样才能检查给定的字符串是否被选中或不在一次搜索。检查给定的listbox项目字符串是否被选中?
]如果可能的话,请在这里发布示例代码。
我给了像'Antony'这样的输入字符串名称。该字符串是列表框项目,并且它也被选中。我怎样才能检查给定的字符串是否被选中或不在一次搜索。检查给定的listbox项目字符串是否被选中?
]如果可能的话,请在这里发布示例代码。
private bool Search(string value)
{
bool ret = false;
foreach (ListItem listItem in ListBox1.Items)
{
if (listItem.Selected && listItem.ToString() == value)
{
ret = true;
break;
}
}
return ret;
}
使用此功能检查......
OR
使用LINQ
private bool Search(string value)
{
return ListBox1.Items.Cast<ListItem>().Any(listItem => listItem.Selected && listItem.ToString() == value);
}
我只是使用多个列表框item.I要选择多个项目我做什么? – Fernando 2012-02-06 10:49:57
现在试试希望他的帮助! – Madhu 2012-02-06 11:08:03
感谢您的快速回复。我会试试这个.. – Fernando 2012-02-06 11:39:03