exclude dinamic value from listbox

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.
 
G

Guest

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

Members online

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top