Click here to Skip to main content
12,820,306 members (28,842 online)
Rate this:
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 using c#.

Narasiman P.
Posted 12-Nov-13 17:44pm
♥…ЯҠ…♥ 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
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:


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.

Rate this: bad
Please Sign up or sign in to vote.

Solution 2

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

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

    Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170308.1 | Last Updated 13 Nov 2013
Copyright © CodeProject, 1999-2017
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