Click here to Skip to main content
15,890,527 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Run mode screen as follows;


i have one list box and one drop down list.

in list box all the student name will display from the database

in the drop down list year will display.

in the run mode user select the student name from the listbox.

if the use did not select the dropdown list, that time shows the message select the Year.

for that how can i validate the dropdownlist using C#


please help me.

Regards,
Narasiman P.
Posted
Comments
Jameel VM 8-May-13 1:38am    
can you post the markup?
Jameel VM 8-May-13 1:39am    
When you want to validate?while listbox selecting event?

While binding dropdownlist add the line below
C#
dropdownlist1.Items.Insert(0, "Select");

And for validation you can write below code in button click
C#
if (dropdownlist1.SelectedItem.Text.Trim() == "Select")
        {
            lblmsg.Text = "Please Select Year";
            dropdownlist1.Focus();
            return;
        }
 
Share this answer
 
v3
User should select from dropdownlist means you may be displaying the first item in dropdownlist as "Select"... and you will have a "Search" or "Show" button in your page.

In that case, you can have a bool variable and change its value inside Dropdownlist selection changed event... So whenever user clicks the "Search" button check the bool value and display an alert based on your requirement
 
Share this answer
 

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