0

这是我需要按字母顺序排列下拉列表项目的“问题”...

这是我的看法

<label for="Contenido">Reparticion</label>  
<div class="control">
    <%: Html.DropDownList ("reparticionId", (SelectList)ViewBag.ReparticionIdSelectList)%>            
</div>
<div class="spacer"></div>
<label>Depósito</label>  
<div class="control">
    <%: Html.DropDownList("deposito", (SelectList)ViewBag.DepositoIdSelectList)%>            
</div>
<div class="spacer"></div>

这是我在控制器中的viewbag ...

private void CargarControlesReparticion() {
    //Crear listado de Reparticion
    this.ViewBag.ReparticionListado = new SelectList(ReparticionNegocio.Listado(), "ReparticionId", "Descripcion");
}

private void CargarControlesDeposito() {
    //Crear Listado Deposito
    this.ViewBag.DepositoListado = new SelectList(DepositoNegocio.Listado(), "DepositoId", "Nombre");
 }

有任何想法吗???谢谢...

4

1 回答 1

0

使用 LINQ 对列表中的项目进行排序

var sortedList = (from entry in ReparticionNegocio.Listado() orderby entry.Value ascending select entry);
this.ViewBag.ReparticionListado = new SelectList(sortedList, "ReparticionId", "Descripcion");
于 2011-06-09T23:15:57.773 回答