Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / DataGrid / November 2006

Tip: Looking for answers? Try searching our database.

Populate a drop down list with a blank entry

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
KatMagic - 12 May 2006 01:40 GMT
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.
Alvin Bruney - 12 May 2006 03:41 GMT
ddl.Items.InsertAt(0, string.empty)

Signature

________________________
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
-------------------------------------------------------

> How can I populate a drop down list with a blank entry so that it is the
> first item in the list?
[quoted text clipped - 14 lines]
> Hope that makes sense.  Basically, my problem would be solved if I could
> add a blank entry first.
KatMagic - 12 May 2006 18:16 GMT
Thanks!  Actually, it's ddl.Items.Insert(0, string.empty) instead of
InsertAt, but you got me in the right direction.

> ddl.Items.InsertAt(0, string.empty)
>
[quoted text clipped - 16 lines]
>> Hope that makes sense.  Basically, my problem would be solved if I could
>> add a blank entry first.
Alvin Bruney - 16 May 2006 00:44 GMT
yup, no wonder code off the top of my head never seems to compile :-)

Signature

________________________
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
-------------------------------------------------------

> Thanks!  Actually, it's ddl.Items.Insert(0, string.empty) instead of
> InsertAt, but you got me in the right direction.
[quoted text clipped - 19 lines]
>>> Hope that makes sense.  Basically, my problem would be solved if I could
>>> add a blank entry first.
clara - 06 Nov 2006 09:36 GMT
I would like to know if the dropdownlist is in datagrid.  I can't use same
method as below to populate it with a blank entry

Please help.

Clara

>How can I populate a drop down list with a blank entry so that it is the
>first item in the list?
[quoted text clipped - 13 lines]
>Hope that makes sense.  Basically, my problem would be solved if I could add
>a blank entry first.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.