How to check if an item exists in a Listbox in asp.net?

How to check if an item exists in a list?
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)) {...} 
+4
source share
2 answers

Try it...

 string toMatch = drp_branch.SelectedItem.Value + "-" + txt_acc_no.Text; ListItem item = ListBox1.Items.FindByText(toMatch); if (item != null) { //found } else { //not found } 
+9
source

you can use this to check if the exsits element is in the list or not ...

 string checkitem = drp_branch.SelectedItem.Value + "-" + txt_acc_no.Text; if ((ListBox1.Items.Contains(checkitem) == true)) { Response.Write("Item exists"); } else { Response.Write("Item not exists"); } 
0
source

Source: https://habr.com/ru/post/1380886/


All Articles