Sorting the HTML dropdown menu (SelectList) in ASP.NET, C# -


in aspx file have: = html.dropdownlist("siteid", viewdata["sites"] selectlist)

in cs file have:

viewdata["sites"] = new selectlist(pr.getunassignedportfoliosites(getauthenticatedcontext(), id), "siteid", "sitename");

it works, however, need sort selectlist nicely sorted when dropdown menu selected.

also, need select 1 item list, , make appear first item visible before dropdown menu clicked.

thank help!

ps have tried looking trough other examples, no luck.

i've changed little bit, looks selectlist has issues set default selected item.

look @ this:

@{   list<selectlistitem> list = (list<selectlistitem>)viewdata["sites"];   list.where(x => x.value == "1").single().selected = true; } @html.dropdownlist("siteid", list.orderby(x => x.selected).thenby(x => x.text)) 

and controller:

        list<selectlistitem> items = new list<selectlistitem>();          items.add(new selectlistitem { text = "action", value = "0" });          items.add(new selectlistitem { text = "drama", value = "1" });          items.add(new selectlistitem { text = "comedy", value = "2" });          items.add(new selectlistitem { text = "science fiction", value = "3" });          viewdata["sites"] = items; 

Comments

Popular posts from this blog

php - Why I am getting the Error "Commands out of sync; you can't run this command now" -

linux - Does gcc have any options to add version info in ELF binary file? -

java - Are there any classes that implement javax.persistence.Parameter<T>? -