Jquery CRUD操作不适用于数据库kendo ui web
我使用剑道网格显示员工数据,并执行创建、更新和删除。读取操作执行得很好,但剩下的三个操作并没有反映回数据库 这是我试过的代码Jquery CRUD操作不适用于数据库kendo ui web,jquery,kendo-ui,Jquery,Kendo Ui,我使用剑道网格显示员工数据,并执行创建、更新和删除。读取操作执行得很好,但剩下的三个操作并没有反映回数据库 这是我试过的代码 <div id="grdCRUD"> </div> <script type="text/javascript"> $(document).ready(function () { dataSource = new kendo.data.DataSource({ transport: {
<div id="grdCRUD">
</div>
<script type="text/javascript">
$(document).ready(function () {
dataSource = new kendo.data.DataSource({
transport: {
read: {
type: "POST",
contentType: "application/json; charset=utf-8",
dataType: "json",
url: "GridWebService.asmx/GetData"
},
update: {
type: "POST",
contentType: "application/json; charset=utf-8",
url: function (EmpNames) {
return "GridWebService.asmx/UpdateEmp" + EmpNames.eid
},
dataType: "json"
},
destroy: {
type: "POST",
contentType: "application/json; charset=utf-8",
dataType: "json",
url: "GridWebService.asmx/DeleteEmp"
},
create: {
url: "",
dataType: "jsonp"
},
parameterMap: function (options, operation) {
if (operation !== "read" && options.models) {
return { models: kendo.stringify(options.models) };
}
}
},
batch: true,
pageSize: 6,
schema: {
data: "d",
model: {
id: "eid",
fields: {
ename: { validation: { required: true} },
age: { type: "number", validation: { required: true, min: 1} },
salary: { type: "number", validation: { required: true, min: 1} }
}
}
}
});
$("#grdCRUD").kendoGrid({
dataSource: dataSource,
pageable: {
refresh: true,
pageSizes: true
},
height: 300,
toolbar: ["create"],
columns: [
{ field: "ename", title: "EmployeeName", width: "150px" },
{ field: "age", title: "EmployeeAge", width: "150px" },
{ field: "salary", title: "EmployeeSalary", width: "100px" },
{ command: ["edit", "destroy"], title: " ", width: "210px" }
],
editable: "popup"
});
});
</script>
这里是我的web服务
[WebMethod]
public List<EmpNames> GetData()
{
SqlDataAdapter da = new SqlDataAdapter("select * from Emp", con);
DataSet ds = new DataSet();
da.Fill(ds, "emp");
return LstEmpNames(ds);
}
public List<EmpNames> LstEmpNames(DataSet ds)
{
List<EmpNames> objenamelst = new List<EmpNames>();
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
EmpNames objemp = new EmpNames();
objemp.eid = Convert.ToInt32(ds.Tables[0].Rows[i][0]);
objemp.ename = ds.Tables[0].Rows[i][1].ToString();
objemp.age = Convert.ToInt32(ds.Tables[0].Rows[i][2]);
objemp.salary = Convert.ToInt32(ds.Tables[0].Rows[i][3]);
objenamelst.Add(objemp);
}
return objenamelst;
}
[WebMethod]
public DataSet DeleteEmp(int id)
{
con.Open();
SqlCommand cmd = new SqlCommand("delete Emp where eid=" + id, con);
cmd.ExecuteNonQuery();
con.Close();
return null;
}
[WebMethod]
public DataSet CreateEmp()
{
con.Open();
SqlCommand cmd = new SqlCommand("Insert into Emp values", con);
cmd.ExecuteNonQuery();
con.Close();
return null;
}
[WebMethod]
public DataSet UpdateEmp(int eid)
{
con.Open();
SqlCommand cmd = new SqlCommand("update emp set ename='SHANKI',age=25,salary=6000 where eid=1", con);
con.Close();
return null;
}
如果代码有误,请提供示例代码。非常感谢。这是一个使用ASP.NET web服务的完整CRUD应用程序: 实现中的问题是方法的签名-检查链接示例中的方法应该是什么样子
有关从JavaScript调用ASP.NET web服务的详细说明,请参阅这篇优秀的博文:感谢您的快速重播。我正在寻找html页面,而不是ASP页面,因为我们完全在html页面中开发应用程序。基于html,您能提供ASP.netHello Korchev I的任何示例代码吗已使用.html页面和web服务。我正在通过web服务将值从DB绑定到网格。但问题是我无法执行更新和删除、插入操作。请确保我没有使用Ajax绑定,只是使用普通数据源。@parsanamoni抱歉,这与原始问题有何关系?