ASP.NET DropDownList / HTML select list default selection -


For my asp.net page, in the back code I load different items / options in a dropdown list but I By specifying selectedindex, the default I notice for postback is set to the selected index number, even if I have never set or changed the focus in the dropdown list.

If the code is not specified in the back or markup, then can the default value of 0 be used for a selected index in a postback with a DropDownList? If yes, this is part of the HTML standard for selection lists, or is it implemented for ASP.NET only?

This is the normal behavior for HTML SELECT control.

As long as the selected property is not used, it will always start with the first item (index of 0).

In many cases, I do not want this in ASP.NET because I want to pick an option specifically to the user.

So what do I do to add an empty item which I can then validate?

i.e.

  & asp: dropdown list runat = "server" datasource id = "AADS" appendabound items = "true" & gt; // final asset & lt; Asp: ListItem text = "Please select an option" value = "" /> & Lt; / ASP: DropDownList & gt;  

In this way, I can set a validation which assumes that the value is empty, the user is compelled to make a selection.


Comments