How do I Dynamically Preselect an item in a html.D

2019-03-30 11:14发布

is there way thats i can preselect an item when the page loads or posts to the server..

this is what i have right now..

<%=Html.DropDownList("dllMonths", 
    new SelectList(new List<string>() {
       "", "January", "Feburary", "March", "April", "June", 
       "July", "August", "September", "October", "November", 
       "December"}), 
    new { onchange="this.form.submit();" })%>

1条回答
Emotional °昔
2楼-- · 2019-03-30 11:58

Set the SelectedValue property of the SelectList, or pass it as second parameter to SelectList constructor.

<% = Html.DropDownList ( "dllMonths", 
                           new SelectList ( new List ( ) 
                                          { "", "January", "Feburary", "March", 
                                            "April", "June", "July", "August", 
                                            "September", "October", "November", 
                                            "December" },
                                          "April" ), 
                           new { onchange = "this.form.submit();" } 
                       )%>
查看更多
登录 后发表回答