views:

784

answers:

1

Hi Everyone,

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();" })%>

Thanx in advance..

Owais

+9  A: 

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();" } )%>

baretta
I would go a little further and say that you should use an overload with the selected item argument.
Craig Stuntz
i think that was what i said :)
baretta
He gave two choices; I'm saying the first is really the only acceptable one. But I did up-vote since he got it right.
Craig Stuntz
Er, I meant the second. :)
Craig Stuntz
yea, actually i would agree on that. It will probably save a function call as well i would think
baretta
Thanx guys that was really helpful..
devforall