我想使用kendo Ui下拉列表根据数据库中所选personid的记录绑定记录。如果isDisable为null,则需要绑定到Please select选项。但是,我有问题。这是我到目前为止的代码:
这是表格:
PersonId PersonName isDisable (bit datatype)
1 Jack False
2 Tony True
3 Brian Null
controller:
TRN_DataAccessLayer.Person data = dbPerson.GetPersonbyID(id);
ViewBag.isDisable= data.isDisable;
在View Razor页面中:
<input type="isDisable" id="isDisable" name="isDisable" style="width:220px; font-size:12px; align:center; font-size:11px; width:156px; length:35px;margin:1.0em 1.5em 5px -10px"/>
<script>
var data= [
{ text: "Yes", value: "1" },
{ text: "No", value: "0" },
];
var cond = parseInt(@ViewBag.isDisable) === 0;
$("#isDisable").kendoDropDownList({
dataTextField: "text",
dataValueField: "value",
dataSource: data,
index: cond ? 0 : 1,
optionLabel: {
text: "Please Select",
value: "-1"
}
});
</script>
答案 0 :(得分:0)
它工作正常,但请确保使用最新的http://cdn.kendostatic.com/2013.2.918/js/kendo.all.min.js
<script src="http://cdn.kendostatic.com/2013.2.918/js/kendo.all.min.js"></script>
有关示例,请参阅此fiddle。