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.