我在Kendo UI上使用MVC应用程序。我们有一个网格,当用户打开行进行编辑时,我们有一个保存公司名称的dropDownList。我试图让DDL默认为与该行相关的公司名称。Kendo UI DropDownListFor Set SelectedValue
这里的列代码:
columns.Bound(e => e.company_business_name).Width(220).Title("Company")
.EditorTemplateName("CompanyName");
和这里的editorTemplate代码:
@model string
@(Html.Kendo().DropDownListFor(m => m)
.DataTextField("Text")
.DataValueField("Value")
.BindTo((System.Collections.IEnumerable)ViewData["Companies"])
)
和填充的DDL的方法:
private void PopulateCompanies()
{
var companyList = new List<SelectListItem>();
if (!string.IsNullOrEmpty(Session["Companies"] as string))
{
companyList = (List<SelectListItem>)Session["Companies"];
}
else
{
companyList = new DataAccess().GetCompanies(CurrentSettings.getUser().userId);
CacheCompanies(companyList);
}
ViewData["Companies"] = companyList;
}
编辑:
更新了码。该DDL仍然填充,但我仍然没有得到选定的值,当我点击网格行上的“编辑”。感觉就像我在这里,帮助!
我建议通过查看自定义编辑器演示开始(http://demos.telerik.com/aspnet-mvc/grid/editing-自定义)和Foreignkey列演示(http://demos.telerik.com/aspnet-mvc/grid/foreignkeycolumn)。请注意,为了查看正在发生的* everything *,您必须打开随Kendo MVC一起安装的演示项目,因为在线MVC演示不会显示每个感兴趣的文件,例如custome编辑器演示,它不会显示EditorTemplate,演示项目应该在这里找到: \ wrappers \ aspnetmvc \示例 –
GetCompanies返回什么?你能发布样本数据吗? – ataravati