Wednesday, October 14, 2009

ASP.NET MVC DropDownList

SelectList elements= new SelectList(new [] {"10", "15", "25", "50", "100", "1000"}, "15");


IList customers = repository.GetAll();
IEnumerable selectList =
from c in customers
select new SelectListItem
{
Selected = (c.CustomerID == invoice.CustomerID),
Text = c.Name,
Value = c.CustomerID.ToString()
};


ViewData["myList"] =
new SelectList(new[] { "10", "15", "25", "50", "100", "1000" }
.Select(x => new {value = x, text = x}),
"value", "text", "15");

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



SelectList sl = new SelectList( new[]{
new SelectListItem{ Text="one", Value="1"},
new SelectListItem{ Text="two", Value="2"},
new SelectListItem{ Text="three", Value="3"}
}, "Text", "Value", "2" );

Referencias:
http://blog.wekeroad.com/blog/asp-net-mvc-dropdownlist-and-html-attributes/

No comments:

PostgreSQL json fields

select name->'es_PE',* from product_template where name->>'es_PE' like '%MEGACI%'   References: [1] https:/...