1
我正在使用Kendo網格來顯示員工數據,並執行創建,更新和刪除。讀取操作表現不錯,但來到其餘三個操作沒有反映回數據庫CRUD操作不適用於數據庫kendo ui web
這裏是我試圖
<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;
}
是什麼,我已經錯過了,或者如果代碼是錯誤的CA ñ你給我任何示例代碼非常感謝。
感謝快速replay.I'm尋找html頁面不是爲ASP頁面,因爲我們正在開發該應用程序完全在HTML頁面。基於Html可以爲您提供任何示例代碼,如您所提供的asp.net –
您好Korchev我已採取.html頁面和Web服務。我通過Web服務綁定從數據庫到網格的值。但問題是我不能做更新和刪除,插入操作。確保我沒有使用Ajax綁定,只需使用正常的數據源。 –
@parsanamoni對不起,這與原始問題有什麼關係? –