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 / Web Controls / November 2007

Tip: Looking for answers? Try searching our database.

Default Value in on Databound Drop Down list

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Randy Galliano - 05 Nov 2007 20:28 GMT
Hello,

I am populating a drop down list control with a table from a database.
I would like the control to display a value such as --- select --- when
it first comes up, instead of any values from the table.  Is there a way
to do this without putting the value --- Select --- in the actual table?

Regards,

Randy.
Nathan Sokalski - 06 Nov 2007 01:36 GMT
Yes, after calling the Databind() method, use the use the Items.Insert()
method. Here is an example:

MyDropDown.DataBind()
MyDropDown.Items.Insert(0,"--- Select ---")

This inserts an extra ListItem before index 0, therefore changing what was
previously index 0 into index 1, index 1 into index 2, etc. Since this is
only 1 extra line of code, it is very little extra work, and makes it the
first ListItem regardless of what is in the database. Hopefully this helps.
Signature

Nathan Sokalski
njsokalski@hotmail.com
http://www.nathansokalski.com/

> Hello,
>
[quoted text clipped - 6 lines]
>
> Randy.
Randy Galliano - 07 Nov 2007 04:30 GMT
Thank you so much.  That worked very well.  I put it in the Page_Load
event so I also added a check for ispostback.

Regards,

Randy.

> Yes, after calling the Databind() method, use the use the Items.Insert()
> method. Here is an example:
[quoted text clipped - 6 lines]
> only 1 extra line of code, it is very little extra work, and makes it the
> first ListItem regardless of what is in the database. Hopefully this helps.

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.