exclude dinamic value from listbox

  • Thread starter Thread starter Mirnes
  • Start date Start date
M

Mirnes

I have a listbox which is populated from Sql query and I use it to add
values to table. I would like to exclude value which just has been
added from listbox. Since it is impossible to do in query which is
datasource for query is there some other option.
 
Hi Mirnes,

You have to handle DataBound of the ListBox event and remove whatever you
don't need:

protected void ListBox1_DataBound(object sender, EventArgs e)
{
ListBox listBox = (ListBox)sender;
// there are two methods you can use
//ListItem listItem = listBox.Items.FindByText("ItemText");
// or
ListItem listItem = listBox.Items.FindByValue("3");
if (listItem != null)
{
listBox.Items.Remove(listItem);
}
}


hope this helps
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top