【问题标题】:How to bind data in ListBox as like gridview in mvc3如何像 mvc3 中的 gridview 一样绑定 ListBox 中的数据
【发布时间】:2013-09-24 09:54:11
【问题描述】:

我想将我的数据绑定到列表框中,就像 mvc 中的网格视图一样

@model IEnumerable<ProjectModel>

@{
     var grid = new WebGrid(
     source: Model,
     rowsPerPage: 4);
}
@grid.GetHtml(
    tableStyle: "grid",
    headerStyle: "header",
    rowStyle: "row",
    footerStyle: "footer",
    alternatingRowStyle: "altRow",
    columns: grid.Columns (
    grid.Column("projectName"),
    grid.Column("ProjectID")
))

就像我们在这个视图中所做的那样。

【问题讨论】:

    标签: asp.net asp.net-mvc-3 gridview razor


    【解决方案1】:

    对于绑定 ListBox 这样做,

      @Html.ListBoxFor(m => m.SelectedValues, 
                           Model.SomeSelectionList.Select(person=> 
                           new SelectListItem 
                           {
                               Text = person.Name, 
                               Value = person.Id, 
                               Selected = // some condition that returns true 
                           }),
                           new { Multiple = "multiple", size = "4"}) 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-02-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-06
      相关资源
      最近更新 更多