【问题标题】:Kendo Grid DropDownList not work剑道网格下拉列表不起作用
【发布时间】:2018-07-23 07:27:43
【问题描述】:

无法在剑道网格中绑定 DropDownList。 如果它不在网格内,它工作正常。 我尝试使用

@(Html.Kendo().DropDownList()
                                      .Name("RegionId")

                                      .OptionLabel("[|[Select...]|]")
                                      .DataTextField("Name")
                                      .DataValueField("Id")
                                      .DataSource(source =>
                                      {
                                          source.Read(read =>
                                          {
                                              read.Action("FindAll", "region")
                                                  .Data("filterRegion");
                                          })
                                           .ServerFiltering(true);

                                      })
                                      .HtmlAttributes(new { @required = "" })
                                      .Enable(false)
                                      .AutoBind(false)
                                      .CascadeFrom("CountryId")
                                       .ValuePrimitive(true).HtmlAttributes(new { @required = "" })
    )

并将其绑定为文本框,而不是下拉列表。 如何让它绑定下拉列表? 注意:这些值在数据库中没有关系,我只需要列并通过代码生成。

【问题讨论】:

  • 您想将下拉列表绑定为Grid 的编辑模板或类似的东西吗?必要时还提供当前网格定义。
  • 是的,我需要作为网格中列的一部分 @(Html.Kendo().Grid() .Name("Users") .Columns(columns => { // 添加 DDl这里}

标签: c# asp.net-mvc-4 kendo-grid kendo-asp.net-mvc


【解决方案1】:

这并不像你想象的那么简单。 整个实现可以在documentation of Telerik中找到。

简而言之,您必须:

  1. 创建一个对象(Text-Value 或 Id-Label)以绑定到您的列
  2. 为这个类创建一个编辑器模板

    @(Html.Kendo().DropDownList()
        .Name("Employee") // The name of the widget should be the same as the name of the property.
        .DataValueField("EmployeeID") // The value of the dropdown is taken from the EmployeeID property.
        .DataTextField("EmployeeName") // The text of the items is taken from the EmployeeName property.
        .BindTo((System.Collections.IEnumerable)ViewData["employees"]) // A list of all employees which is populated in the controller.
    )
    
  3. [UIHint("ObjectEditor")]装饰您的财产

【讨论】:

  • 感谢我的 [UIHint("ObjectEditor")] 问题
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-29
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多