htmlasp.net-mvcmodel-view-controllerdrop-down-menuselectedvalue

How to set one of the values in dropdownlist as selectedvalue in asp.net mvc?


I have a dropdownlist with values -1,1,2 and text A,B,C i wanna set B as selectedValue by default when the page is loaded.

Something which can be done at the Page Level i.e in aspx or ascx.


Solution

  • You need to specify "selected" attribute of html "select" tag.

    One option is - render select tag on your own.

    Second - make sure that you form correct SelectItemList ('datasource' for your dropdownlist) - it must contain one item with .Selected=true.