How to check if an item already exists in a listbox

Platform: ASP.NET| Category: ListBox

VB.NET


Dim lstitem As ListItem = ListBox1.Items.FindByValue('<valuecheckedfor>')
If Not lstitem Is Nothing Then
       Response.Write('Item Exists')
Else
       Response.Write('Item Does not exist')
End If

C#


ListItem lstitem    = ListBox1.Items.FindByValue('<valuecheckedfor>');
if (  lstitem !=null)
{
	Response.Write ('Does  exist');
}
else
{
	Response.Write ('Does not exist');
}

You can also use FindByText instead of FindByValue.

Share with

Related FAQs

Couldn't find the FAQs you're looking for?

Please submit your question and answer.