簡體   English   中英

Kendo Grid DropDownList不起作用

[英]Kendo Grid DropDownList not work

無法在劍道網格中綁定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 = "" })
    )

並將其綁定為文本框,而不是下拉列表。 如何使其綁定下拉列表? 注意:這些值在數據庫中沒有關系,我只需要按代碼列並將其建立即可。

這並不像您認為的那么簡單。 整個實現可以在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")]裝飾您的媒體資源

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM