Click here to Skip to main content
11,430,708 members (70,341 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
My code as follows

Student ID Dropdownlist1

Course Dropdownlist2

Course timings Dropdownlist3


i want to validate if any of the above 3 Dropdownlist is not selected want to show the message "Please select"


for that how can i validate drodpownlist in asp.net using c#.


Regards,
Narasiman P.
Posted 12-Nov-13 17:44pm
Comments
♥…ЯҠ…♥ at 12-Nov-13 22:59pm
   
Show the message where? and you want common function to validate all the drop down list? where you wanna validate in button click event or where?
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Hi Narasiman,

To validate the dropdownlist selection property you can use this function
protected void ValidateDDL(DropDownList ddl)
        {
            if (ddl.SelectedIndex == -1) //Customize index value 
            {
                //Throw your error here
            }
        }
Function Call:
 
ValidateDDL(Dropdownlist1);
ValidateDDL(Dropdownlist2);
ValidateDDL(Dropdownlist3);
Same can also validate using Javascript, it depends on you...
function validate()
{
   if(document.getElementById("ddlList").value == "")
   {
      alert("Please select value"); // prompt user
      document.getElementById("ddlList").focus(); //set focus back to control
      return false;
   }
}
Hope this helps you a bit.

Regards,
RK
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Check out this..
This will help you.
Link 1 [^]
Link 2 [^]
  Permalink  
v2

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



Advertise | Privacy | Mobile
Web04 | 2.8.150428.2 | Last Updated 13 Nov 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100