How to add a RequiredFieldValidator to DropDownList control?

前端 未结 4 822
青春惊慌失措
青春惊慌失措 2020-11-29 01:51

I have a DropDownList binded with aSqlDataSource to display the values from the database.

I am unable to validate using a RequiredFie

4条回答
  •  情深已故
    2020-11-29 02:12

    For the most part you treat it as if you are validating any other kind of control but use the InitialValue property of the required field validator.

    
    

    Basically what it's saying is that validation will succeed if any other value than the 1 set in InitialValue is selected in the dropdownlist.

    If databinding you will need to insert the "Please select" value afterwards as follows

    this.ddl1.Items.Insert(0, "Please select");
    

提交回复
热议问题