Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I check whether an item exists in Listbox in asp.net?

How do I check whether an item already exists in a Listbox?
I am using VS 2008 ASP.NET 3.5 framework C#. I used the following code...

 if (ListBox1.Items.Contains(drp_branch.SelectedItem.Value + "-" + txt_acc_no.Text))
 {...}
like image 330
David John Avatar asked Dec 22 '22 06:12

David John


1 Answers

Try this...

string toMatch = drp_branch.SelectedItem.Value + "-" + txt_acc_no.Text;
ListItem item = ListBox1.Items.FindByText(toMatch);
if (item != null)
{
    //found
}
else
{
    //not found
}
like image 71
Naeem Sarfraz Avatar answered Feb 19 '23 09:02

Naeem Sarfraz