简体   繁体   English

Kendo Grid DropDownList不起作用

[英]Kendo Grid DropDownList not work

Cannot bind DropDownList in kendo grid. 无法在剑道网格中绑定DropDownList。 it works fine if it's not inside the grid. 如果它不在网格内,则可以正常工作。 I try to use 我尝试使用

@(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 = "" })
    )

and its bind as a text box, not drop-down list. 并将其绑定为文本框,而不是下拉列表。 how to make it bind drop-down list? 如何使其绑定下拉列表? note: the values do not have a relation in a database I need to just columns and make it by code. 注意:这些值在数据库中没有关系,我只需要按代码列并将其建立即可。

It is not as simple as you may think I am afraid. 这并不像您认为的那么简单。 The entire implementation can be found in the documentation of Telerik . 整个实现可以在Telerik文档中找到。

In a few words you have to: 简而言之,您必须:

  1. Create an object (Text-Value or Id-Label) to bind to your column 创建一个对象(Text-Value或Id-Label)以绑定到您的列
  2. Create an editor template for this class 创建此类的编辑器模板

     @(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. Decorate your property with [UIHint("ObjectEditor")] [UIHint("ObjectEditor")]装饰您的媒体资源

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM