Asp net validating drop down lists

Now you will add drop-down lists to the Rating column, or column B. In the Data Tools section, click the Data Validation button.

asp net validating drop down lists-12

In other words, if the user selects "Chocolate" and clicks Submit to post the form to the server, your controller might detect a validation error and re-render the form with validation messages.

The drop down list will also re-build the from scratch, but somehow "Choclate" is selected instead of "Select A Flavor".

You'll see this behavior because Drop Down List For will peek in Model State to see the last value for Selected Flavor Id, and build the drop down list with the last selected flavor marked as selected.

It's the same magic Web Form programmers see with View State.

Note: Above both j Query codes will work only with j Query 1.7 or higher version as I have used .on() method to bind the click event and was introduced in j Query 1.7.