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.
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.
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.
Haven't checked for syntax but you can do something like this in your get controller...
ViewData[ddlItems] = new SelectList(new List<string>() { "1", "1", "2", "A", "B", "C"}, "B");
And in your view...
<%= Html.DropDownList("ddlItems", (SelectList)ViewData[ddlItems], String.Empty, null)%>