如何在asp中的自定义弹出窗口(通过html数据属性)中的dropdownlist中添加默认项(--Select--)剑

How to add the Default Item (--Select--) in dropdownlist in custom popup (via html data attributes)kendo Grid in asp

本文关键字:dropdownlist 中的 添加 默认 --Select-- 数据属性 html 自定义 通过 窗口 asp      更新时间:2023-09-26

am在单个网格中使用剑道内联和弹出式编辑我使用了弹出式网格的自定义模板<script id="customPopUpTemplate" type="text/x-kendo-template">
<form id="myForm" action="" method="post">
<div class="k-edit-field">
<input name="LoginName" class="k-textbox"/>
<span id="sta3" style="color: Red; font-size:medium;"> </span>
</div><div class="div">Login Name: </div>

`<div class="k-edit-field">`<br>
  `  <input name="Password" type="Password"  class="k-textbox"/> `<br>

<span id="sta4" style="color: Red; font-size:medium ;"> * </span>
</div> <div class="div">Password: </div>
<div class="k-edit-field">
<input name="ScopeId"
data-bind="value:ScopeId"
data-value-field="ScopeId"
data-text-field="ScopeName"
data-source="DataSourceScopepopup"
data-role="dropdownlist" /> <span id="sta6" style="color: Red; font-size:medium ;"> </span>

</div><div class="div">Scope: </div>

</form>

var DataSourceScopepopup = new kendo.data.DataSource(
{
transport:
{
read:
{
url: "WebServices/Project.asmx/GetScopepopup",
data: "{}",
contentType: 'application/json; charset=utf-8',
type: 'POST',
dataType: 'json'
},
parameterMap: function(options, operation)
{
if (operation == 'read')
return kendo.stringify(options);
}
},
schema:
{
data: function(Data)
{
return (Data.d);
},
model:
{
id: "ScopeName",
fields:
{
ScopeId: { type: "number"},
ScopeName: { type: "string"}
}
}
},
error: function(e)
{
var xhr = e[0];
var statusCode = e[1];
var errorThrown = e[2];
alert('DataSourceScope - ' + xhr + ', ' + statusCode + ', ' + errorThrown);
}
});

这是我的编码如何在下拉列表中添加默认项--选择?现在我只得到数据库项,,,如何添加它?提前感谢

在模板中添加属性数据选项label="--Select--"

 <input name="ScopeId"
    data-bind="value:ScopeId"
    data-value-field="ScopeId"
    data-text-field="ScopeName"
    data-source="DataSourceScopepopup"
    data-role="dropdownlist" 
   data-option-label="--Select--"  <!- display default value-->
    />

由于您使用的是绑定元素,我会更改SQL语句或服务,以便将您想要的值添加到返回的值列表中。

否则,您可以使用数据绑定事件向列表中添加一个新项目,如下所示:

dataBound: function () {
if (DataSourceScopepopup.at(0). !== "--Select--") {
    DataSourceScopepopup.insert(0, { ScopeId: 0, ScopeName: "--Select--" });
}