Click here to Skip to main content
14,732,694 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:

I have a dropdownlist that is bound to data in the code behind.
i want the default to be -- None -- at the top of the list.
if the user select the top of list i.e --None-- it should prompt as pl z select from the list ,
if user select the other than --None-- then it should continue the process

i have added the top list as
drop down.Items.Insert(0, new ListItem("-- None--", "")) 

how to validate

thanks in advance
Updated 6-Mar-12 6:07am
Jyothikarthik_N 6-Mar-12 10:32am
Is it a Web Project or a windows Project?

Please tag the question with proper areas.
pradeep manne 6-Mar-12 10:34am
its a web project

use this one.
drop down.Items.Insert(0, new ListItem("-- None--", "-- None--"));
dropdownlist1.Items.Insert(0, new ListItem("None", "0"));

for validating you can use javascript for example

  if(dropdownlist1.SelectedValue == "0")
     throw new Exception("<script language="javascript">" + "alert('Please select something');" + "");

catch (Exception ex)
   label1.Text = ex.Message;
function validateDropDown(){
           alert('please select valid item.');
           return false;
Set the AppendDataBoundItems property in the markup and add an ListItem. Add a RangeValidator and have it validate the DropDownList. If the value for the ListItem added in the markup is -1, for instance, then you would set the MinValue for the RangeValidator to 0.

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