I know I can just insert (<asp:ListItem Value="">Please select</asp:ListItem>)
But by doing this, if the user doesn't select the name, still he/she is able to submit the form and I am using "Value" for e-mail address and in t hat case, a blank value if passed without any e-mail address and it throws an error.
How to add a first blank value in t he dropdown list and put a validation that the user HAVE to select his/her name ?
Add this line to include Please Select as the first item in dropdown list
<asp:ListItem Value="Please Select">Please Select</asp:ListItem>
Then, add the RequiredField Validator and set its initial value to "Please Select" to make sure user have to select something other than the initial value
jeffcarter
Member
698 Points
919 Posts
How to make first value of dropdownlist as blank ?
May 18, 2012 02:50 PM|LINK
I want to add a top value in the dropdown list as "Please select" in the following code:
I know I can just insert (<asp:ListItem Value="">Please select</asp:ListItem>)
But by doing this, if the user doesn't select the name, still he/she is able to submit the form and I am using "Value" for e-mail address and in t hat case, a blank value if passed without any e-mail address and it throws an error.
How to add a first blank value in t he dropdown list and put a validation that the user HAVE to select his/her name ?
Ravi Kumar K...
Member
727 Points
155 Posts
Re: How to make first value of dropdownlist as blank ?
May 18, 2012 02:55 PM|LINK
hoopslife
Contributor
2477 Points
483 Posts
Re: How to make first value of dropdownlist as blank ?
May 18, 2012 02:55 PM|LINK
Use a validator. Check this out:
http://stackoverflow.com/questions/5089016/validator-for-drop-down-list-in-asp-net
Blog
AccuWebHosti...
Contributor
2212 Points
401 Posts
Re: How to make first value of dropdownlist as blank ?
May 18, 2012 03:25 PM|LINK
Hi!
Try following code:
Hope this will work for you.
Regards.
Top Windows VPS Provider
jeffcarter
Member
698 Points
919 Posts
Re: How to make first value of dropdownlist as blank ?
May 18, 2012 03:28 PM|LINK
Thank you everyone