|
.net
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Inserting a default ListItem in DropDownList ControlI want to insert a default null ListItem with the text "choose an item ..."
in my DropDownList control. I have seen similar postings here regarding this issue but all of them seem to focus around having to populate datasources, datatables etc. and then bind the DropDownList in the codebehind of the .aspx page. I am using Visual Studio 2005 and the .NET Framework 2.0. I thought that with all these new improvements we could avoid all of the irritations of ..NET Framework 1.x and the weak controls that came with the IDE by being able to automate all of this databinding stuff. It seems like the only way to insert individual ListItems is if you go back to doing everything in code. What gives? Thanks in advance. [...databinding code...]
ListItem Choose = new ListItem("Choose..."," "); this.ddlMyDropDownList.Items.Insert(0,Choose); The 0 in Items.Insert is the item index in the dropdown list. Also, you must use a space within the two quotes for it to work properly. The above will create a "Choose..." at the top of your databound drop-down list (which is great as long as you databound only for purposes of populating the list). I prefer to create a blank one instead...new ListItem(" "," ")...and then use client-side javascript...document.all['ddlMyDropDownList'].selectedIndex != 0...to validate that something has been chosen.
Other interesting topics
Issue with ASP.NET 2.0 Global asax
Seeking examples of screen scraping.... Help: ASP.Net broken (tried usual suspects...) Can't open asp xml page Question about string Error: 'CreateUser' is not a member of 'Membership' vs2005: domain trust relationship problem FormsAuthentication.SignOut() and User.Identity What is the database "standard" in 2.0? XMLHTTP question |
|||||||||||||||||||||||