Check list box before entering a record
<p>In <code>ASP.NET/C#</code> how to check if the <code>listbox</code> has a duplicate value before entering a value from <code>textbox</code>.</p>

<p>I tried</p>

<pre><code>If(ListBox1.Items.Contains(TextBox1.Text))
{
 // do nothing
}
else
{
 ListBox1.Items.Add(TextBox1.Text);
}
</code></pre>

<p>I am getting error at first line.</p>
