Validating dropdown list selection in asp c sharp
Data Value Field = "Report Type ID"; ddl Report Type. Insert(0, new List Item("--Select--", "0")); //ddl Report Type.
If you want to force to select an Item of a Drop Down List rather than default selection you have to add a List Item like “–Please Select–” as an Item.In Asp.net, sometimes we need to validate List Box and Drop Down List using Required field validator.It is tricky and avoids the use of Java Script function to validate List Box and Drop Down List. For validating Drop Down List, make sure you have "--Select--" option value 0 other wise validation on it will not work.In this scenario if you add a Required Field Validator, the validator can not validate the Drop Down List.To do that you have to mention Required Field Validator Initial Value property =”0″.You are provided with sample code for using each of the standard validation controls.
Next, we extend the basic validation controls with our own custom validation controls.
For example, you learn how to create an control is associated with each of the three form fields.
If you attempt to submit the form in Listing 3.1 without entering a value for a field, then a validation error message is displayed (see Figure 3.1). Notice that there is nothing wrong with associating more than one validation control with a form field.
Control Creating Custom Validation Controls Summary In this chapter, you learn how to validate form fields when a form is submitted to the web server.
In the first part of this chapter, you are provided with an overview of the standard validation controls included in the ASP. You learn how to control how validation errors are displayed, how to highlight validation error messages, and how to use validation groups.
In this article I try to explain how to validate Drop Down List and List Box using Required Field Validator.