Click here to Skip to main content
15,884,908 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
in dropdown list i have use list item. in list item i have to put 'please select' at first list item and this will not be consider as data.then how to do this?
Posted
Updated 2-Jan-13 21:28pm
v2
Comments
prashant patil 4987 3-Jan-13 3:29am    
can you clear your question in detail?
Sampath Kumar Sathiya 3-Jan-13 3:35am    
You need check the selected index and avoid that.

HTML
<select name="dropdown" id="dropdown">
 <option value="" selected disabled>Please select</option>
 <option value="value1" >Value 1</option>
 <option value="value2" >Value 3</option>
</select>


Please note the disabled attribute. Browsers should not allow this to be selected. But if, you can check in code (either on client side and/or server) the empty value.
 
Share this answer
 
Comments
ridoy 3-Jan-13 5:28am    
+5
Zoltán Zörgő 3-Jan-13 5:31am    
Thank you.
I think while validating the DropDownList you are getting problem, right? If yes then go to the RequiredFieldValidator controls, which you are using to validate the DropDownList and set the InitialValue of the RequiredFieldValidator as "please select" . This will avoid your selection if you have selected "please select" item from your DropDownList and make sure the value for that listitem is "please select".

Check more referances Here[^].


--Amit
 
Share this answer
 
v2
hi,

XML
<select name="dropdown" id="dropdown">
 <option value="-1">Please select</option>
 <option value="value1" >Value 1</option>
 <option value="value2" >Value 3</option>
</select


Use asp required field validator with "initial value=-1", to restrict user to select "please select".
 
Share this answer
 
v2
Comments
Zoltán Zörgő 3-Jan-13 3:47am    
Wroooo, brother...! It would be nice to change a little bit more, before using my answer...
[no name] 3-Jan-13 3:52am    
but bro i think this is the correct & use friendly way....isn't it :-)
ridoy 3-Jan-13 5:28am    
+5
[no name] 3-Jan-13 5:32am    
thanks
Praveen_P 4-Dec-14 8:07am    
+5 !
just use an if clause

something like this

VB
If ddl.SelectedText = "Please Select" then
  msgbox "Invalid Selection"
  End
Else
   'Put in your code here
End If
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900