我有一个webservice和jqgrid,我想用数据库表加载jqgrid
getdata()
如果我的代码不对,请告诉我它不对的地方
[的WebMethod]
public string getdata()
{
SqlConnection con=new SqlConnection(ConfigurationManager.ConnectionStrings["connection"].ToString());
SqlCommand cmd = new SqlCommand("select * from customer", con);
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(cmd);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
da.Fill(ds);
string data=JsonConvert.SerializeObject(ds);
return data;
}
我的脚本代码是:
<script>
$(document).ready(function () {
jQuery("#jqgriddemo").jqGrid({
url: "http://localhost:62442/WebServices/MyWebService.asmx" + "/" + "getdata",
contentType: "application/json; charset=utf-8",
datatype: "json",
colNames: ['Id', 'First Name', 'Last Name'],
colModel: [
{ name: 'id', index: 'id', width: 20, stype: 'text' },
{ name: 'FirstName', index: 'FirstName', width: 150 },
{ name: 'LastName', index: 'LastName', width: 150 },
],
rowNum: 10,
sortname: 'id',
loadonce: true,
rowlist: [10, 20, 30],
mtype: 'POST',
pager: '#pager',
viewrecords: true,
sortorder: 'desc',
caption: 'First Jqgrid',
serializeGridData: function (postData) {
return JSON.stringify(postData);
},
jsonReader: {
root: "d.rows",
page: "d.page",
total: "d.total",
records: "d.records",
repeatitems: false,
userdata: "userdata"
},
});
});
请告诉我更好的方法,或者为我提供解决此问题的链接。