【发布时间】:2014-11-02 18:47:24
【问题描述】:
如何在单击编辑按钮时在 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(
{
传输:
{
读取:
{
url: "WebServices/Project.asmx/GetScope",
data: "{}",
contentType: '应用/json; charset=utf-8',
type: 'POST',
dataType: 'json'
},
parameterMap: function(options, operation)
{
if (operation == 'read')
return kendo.stringify(options);
}
},
schema:
{
data: function(Data)
{ @987654364 @return (Data.d);
},
型号:
{
id: "ScopeId",
字段:
{
ScopeId: { type: "number"},
ScopeName: { 类型:“字符串”}
}
}
},
错误:函数(e)
{<br>
var xhr = e[0];
var statusCode = e[1];
var errorThrown = e[2];
alert('DataSourceScope - ' + xhr + ', ' + statusCode + ', ' + errorThrown);
}<br>
}) ;
function ScopeDropDownEditor(container, options)
{
$('
data-bind="value:' + options.field + '"/>')
.appendTo(container)
.kendoDropDownList(
{
autoBind: false,
dataSource: DataSourceScope
});
} `
在我的网络服务代码中
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;
}
没关系.. 但是在单击编辑按钮后,下拉列表项目如第一项 例如
ScopeName id 下拉列表 项目管理员、开发人员、测试人员
在数据库中 james 是测试员 如果我点击编辑按钮意味着
Name ScopeName James admindevelopertester
如何绑定以及如何显示选定的项目? 提前谢谢。
【问题讨论】:
标签: javascript asp.net kendo-ui kendo-grid kendo-asp.net-mvc