开发者

Selectlist and dropdownlist

I'd like to create a dropdownlist from following structure

List<KeyValuePair<long, string>> sponsori = 
    new List<KeyValuePair<long, string>>();

Now I want the selectlist to have the pair's long as data value, th开发者_运维知识库e string as text value and the selected item, if I have only access to the long of the selected item.

THanks in advance.


In your action code

 yourViewModel.Sponsori= new SelectList(sponsori, "Key", "Value")

In your view code

<%=Html.DropDownList("yourSelectid", Model.Sponsori) %>


ViewData["selectList"] = new SelectList(sponsori, "Key", "Value");

And then on the page:

<%= Html.DropDownList("selectList") %>

You can also check out Rendering a Form in ASP.NET MVC Using HTML Helpers for a similar example (and more documentation).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜