Populate a drop down list with a blank entry

Discussion in 'ASP .Net Datagrid Control' started by KatMagic, May 12, 2006.

  1. KatMagic

    KatMagic Guest

    How can I populate a drop down list with a blank entry so that it is the
    first item in the list?

    I tried:
    ddl.Items.Add(New ListItem(" ", 0))

    And then getting a dataset and binding it to the ddl, which of course loses
    the blank item. If I run the above after binding the dataset, the blank
    entry is at the end of the list. The problem with that is in several places
    in my application, I select an item in the drop down list according to a
    value. If the value is not found, it returns 0. If I select the drop down
    list according to that 0, it displays the first item in the list, which is
    incorrect. If I check for a 0 value, then select the blank entry if it's
    zero, then the value that actually does point to the first item isn't found.

    Hope that makes sense. Basically, my problem would be solved if I could add
    a blank entry first.
     
    KatMagic, May 12, 2006
    #1
    1. Advertising

  2. KatMagic

    KatMagic Guest

    Thanks! Actually, it's ddl.Items.Insert(0, string.empty) instead of
    InsertAt, but you got me in the right direction.

    "Alvin Bruney" <www.lulu.com/owc> wrote in message
    news:OELh$...
    > ddl.Items.InsertAt(0, string.empty)
    >
    >
    > --
    >
    > ________________________
    > Warm regards,
    > Alvin Bruney [MVP ASP.NET]
    >
    > [Shameless Author plug]
    > Professional VSTO.NET - Wrox/Wiley
    > The O.W.C. Black Book with .NET
    > www.lulu.com/owc, Amazon
    > Blog: http://www.msmvps.com/blogs/alvin
    > -------------------------------------------------------
    >
    > "KatMagic" <> wrote in message
    > news:...
    >> How can I populate a drop down list with a blank entry so that it is the
    >> first item in the list?
    >>
    >> I tried:
    >> ddl.Items.Add(New ListItem(" ", 0))
    >>
    >> And then getting a dataset and binding it to the ddl, which of course
    >> loses the blank item. If I run the above after binding the dataset, the
    >> blank entry is at the end of the list. The problem with that is in
    >> several places in my application, I select an item in the drop down list
    >> according to a value. If the value is not found, it returns 0. If I
    >> select the drop down list according to that 0, it displays the first item
    >> in the list, which is incorrect. If I check for a 0 value, then select
    >> the blank entry if it's zero, then the value that actually does point to
    >> the first item isn't found.
    >>
    >> Hope that makes sense. Basically, my problem would be solved if I could
    >> add a blank entry first.
    >>
    >>
    >>

    >
    >
     
    KatMagic, May 12, 2006
    #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. Miguel Dias Moura

    Populate a Drop Down List

    Miguel Dias Moura, Jun 12, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    22,102
    DalePres
    Jun 12, 2004
  2. =?Utf-8?B?TWFyZHk=?=

    Populate a label with text from a drop down list box

    =?Utf-8?B?TWFyZHk=?=, Jul 26, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    455
    Eliyahu Goldin
    Jul 27, 2005
  3. weiwei
    Replies:
    0
    Views:
    1,073
    weiwei
    Jan 5, 2007
  4. Replies:
    5
    Views:
    317
  5. user

    Populate drop down list

    user, Dec 8, 2009, in forum: Javascript
    Replies:
    1
    Views:
    136
Loading...

Share This Page