我在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