exclude dinamic value from listbox

Discussion in 'ASP .Net' started by Mirnes, Jun 22, 2007.

  1. Mirnes

    Mirnes Guest

    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.
    Mirnes, Jun 22, 2007
    #1
    1. Advertising

  2. 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
    --
    Milosz


    "Mirnes" wrote:

    > 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.
    >
    >
    =?Utf-8?B?TWlsb3N6IFNrYWxlY2tpIFtNQ0FEXQ==?=, Jun 22, 2007
    #2
    1. Advertising

  3. Mirnes

    Mirnes Guest

    Thanks for response, I'll try this.


    Milosz Skalecki [ MCAD ] je napisao:
    > 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
    > --
    > Milosz
    >
    >
    > "Mirnes" wrote:
    >
    > > 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.
    > >
    > >
    Mirnes, Jun 25, 2007
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Alessandro

    Problems with Dinamic controls

    Alessandro, Jul 16, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    415
    Cristian Suazo
    Jul 16, 2003
  2. Damir

    Dinamic images

    Damir, May 6, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    380
    Damir
    May 6, 2005
  3. whois
    Replies:
    12
    Views:
    592
    Roedy Green
    Jun 22, 2004
  4. Novello

    dinamic classloader?

    Novello, Jul 1, 2005, in forum: Java
    Replies:
    3
    Views:
    345
    Chris Smith
    Jul 1, 2005
  5. Roberto Dias
    Replies:
    1
    Views:
    752
    Paolo Alexis Falcone
    Jun 30, 2004
Loading...

Share This Page