Click to See Complete Forum and Search --> : DropDown List start blank
Shaitan00
February 12th, 2005, 01:40 AM
Given a dropdown list box [ddlList] populated by a dataset [oRecs].
It seems that when populated (datasource) the dropdown list automatically selects/displays the first item in the list
However I want the user to be FORCED to select something (and not have the first item appear automatically), how can I force the DropDrop list to start blank?
So that if I do ddlList.Selectedindex I get -1 until the user manually selects something.
anand_chavali
February 12th, 2005, 02:40 AM
Hi,
I was also struck with the same problem in using the ComboBox in VC++.......I solved my problem like follows:
Insert a blank text as the first entry in the combo box and make it as selected at the first go.......so check what user selects in ur "submit" code.....and if the selected index in combo box is 0....then it means that user hasn't selected any thing.............
Hope this will help u atleast a bit.....
Regards,
Anand.
Shaitan00
February 12th, 2005, 10:07 PM
Great idea but it doesn't seem to work for me.
If I add the EMPTY/BLANK before and between the .Datasource and .Databind then nothing happens (looks like the .Databind overrides what I added manually?)
If I put it Afterwards the item is added at the end of the list.
I need the blank/empty to be the 1st thing in the dropdown so I can set that starting index = 0.
Any clues how I can get around this?
Sukim
February 13th, 2005, 07:03 PM
Hi,
After the databinding is done you can add a new option to the list as below.
ddlList.DataSource = dsDataSource
ddlList.DataBind()
ddlList.Items.Insert(0,"Choose any one")
ddlList.SelectedIndex = 0
Is that helpfull????
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.