ListBox (WebControls)

Discussion in 'ASP .Net' started by =?Utf-8?B?bWc=?=, Feb 9, 2004.

  1. How can I remove (using C#) the items previously added to a System.Web.UI.WebControls.ListBox
     
    =?Utf-8?B?bWc=?=, Feb 9, 2004
    #1
    1. Advertising

  2. =?Utf-8?B?bWc=?=

    dm_dal Guest

    To remove all the items, use the following:

    foreach(ListItem item in ListBox1.Items)
    {
    ListBox1.Items.Remove(item);
    }


    If your just wanting to remove a single item you can use the following:

    ListBox1.Items.RemoveAt(n); where n is the index of the item you want to
    remove.


    If you don't know the index of the item, then you can use:

    ListItem item = ListBox1.Items.FindByValue(foo); where foo is a string
    representing the value you're looking for.
    ListBox1.Items.Remove(item);
    or;
    ListItem item = ListBox1.Items.FindByText(foo); where foo is a string
    representing the text you're looking for.
    ListBox1.Items.Remove(item);

    Of course, replace "ListBox1" with the name of your ListBox control.

    David Young

    "mg" <> wrote in message
    news:D...
    > How can I remove (using C#) the items previously added to a

    System.Web.UI.WebControls.ListBox
     
    dm_dal, Feb 9, 2004
    #2
    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. Richard
    Replies:
    6
    Views:
    653
    Richard
    Jun 13, 2004
  2. Replies:
    0
    Views:
    355
  3. mg

    ListBox (WebControls)

    mg, Feb 9, 2004, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    113
  4. kk

    WebControls.Listbox

    kk, Aug 25, 2004, in forum: ASP .Net Web Controls
    Replies:
    2
    Views:
    108
    Andrea Williams
    Aug 25, 2004
  5. Jason Wood
    Replies:
    1
    Views:
    187
    Bob Barrows [MVP]
    May 25, 2005
Loading...

Share This Page