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))
{...}
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
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With