Thursday, August 30, 2012

Make a list box search


You need a listbox with items, a textbox and a button.


protected void Button1_Click(object sender, EventArgs e)
    {
        ListBoxPolicies.SelectedIndex = -1;

        for(int i=0; i< ListBox1.Items.Count; i++)
        {
            if (ListBox1.Items[i].ToString().Contains(TextBox1.Text))
            {
                ListBox1.SelectedIndex = i;
            }
        }
    }

No comments:

Post a Comment