如何在Kendo Grid中显示所选项目,同时单击“编辑”按钮 **我的编码就像**
var grid= $("#DivUser").kendoGrid(
{
dataSource: DataSource4,
scrollable: true,
sortable: true,
filterable: false,
reorderable: true,
resizable: true,
pageable: true,
toolbar: [ { text : "Add new record", name: "popup",
iconClass: "k-icon k-add"} ],
editable : {
mode : "inline"
columns: [
{
field: "LoginName",
title: "Login Name",
width:"175px"
},
{
field: "ScopeId",
title: "Scope Id",
editor: ScopeDropDownEditor
},
{
command: ["edit", "destroy"],
title: " ",
width: "175px"
}
]
}).data("kendoGrid");
var DataSourceScope = new kendo.data.DataSource(
{
传输:
{
读取:
{
网址:“WebServices / Project.asmx / GetScope”,
数据: “{}”,
contentType:'application / json; charset = utf-8',
类型:'POST',
dataType:'json'
},
parameterMap:function(options,operation){{ 1}} {
if(operation =='read')
返回kendo.stringify(options);
}
},
schema :
{
数据:function(Data)
{
return(Data.d);
},
模型:
{
id:“ScopeId”,
字段:
{
ScopeId :{type:“number”},
ScopeName:{type:“string”}
}
}
},
错误:函数(e)
{
var xhr = e [0]; <br>
var statusCode = e [1];
var errorThrown = e [2]; {{ 1}} alert('DataSourceScope - '+ xhr +','+ statusCode +','+ errorThrown);
}
});
函数ScopeDropDownEditor(容器,选项) )<br>
{
$('
data-bind =“value:'+ options.field +'”/>')
.appendTo(container)
.kendoDropDownList(
{
autoBind :false,
dataSource:DataSourceScope
});
}`
在我的网络服务代码中,如
这是好的.. 但点击“编辑”按钮后,下拉列表项目就像第一项一样 例如
ScopeName id下拉列表 items Admin,Developer,tester
在数据库中詹姆斯是测试人员 如果我单击编辑按钮手段
public class Scopes
{
int _ScopeId;
string _ScopeName;
public int ScopeId
{
get { return _ScopeId; }
set { _ScopeId = value; }
}
public string ScopeName
{
get { return _ScopeName; }
set { _ScopeName = value; }
}
public Scopes() { }
public Scopes(int ScopeId, string ScopeName) { this.ScopeId = ScopeId; this.ScopeName = ScopeName; }
}
[WebMethod]
public List<Scopes> GetScope()
{
string StrConnectionString = ConfigurationManager.ConnectionStrings["sample"].ConnectionString;
SqlConnection SqlConnection1 = new SqlConnection(StrConnectionString);
SqlCommand SqlCommand1 = new SqlCommand("select distinct ScopeId,(select ScopeName from Scope2 where Scope2.ScopeID=User2.ScopeId)as ScopeName from User2", SqlConnection1);
DataTable DataTable1 = new DataTable();
SqlDataAdapter SqlDataAdapter1 = new SqlDataAdapter(SqlCommand1);
SqlDataAdapter1.Fill(DataTable1);
List<Scopes> ListScope = new List<Scopes>();
foreach (DataRow DataRow1 in DataTable1.Rows)
{
ListScope.Add(new Scopes(Convert.ToInt32(DataRow1["ScopeId"]), Convert.ToString(DataRow1["ScopeName"])));
}
return ListScope;
}
Name ScopeName
James admin
如何绑定以及如何显示所选项目? 谢谢你提前。
答案 0 :(得分:0)
编辑
使用java脚本直接获取数据
var xhReq = new XMLHttpRequest();
xhReq.open("POST", 'WebServices/Project.asmx/GetScope', false);
xhReq.send(null);
var DataSourceScope = JSON.parse(xhReq.responseText);
function ScopeDropDownEditor(container, options)
{
$('<input name="' + options.field + '"/>').appendTo(container).kendoDropDownList({
dataTextField: "ScopeName",
dataValueField: "ScopeId",
dataSource: DataSourceScope.d
});
}