Ill give the input string name like 'Antony'. That string was listbox item and its also selected. How can i check whether the given string is selected or not with in a single search.
]If its possible means please post the sample code here.
Join Stack Overflow to learn, share knowledge, and build your career.
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;
}
check using this function ...
OR
using LINQ
private bool Search(string value)
{
return ListBox1.Items.Cast<ListItem>().Any(listItem => listItem.Selected && listItem.ToString() == value);
}