Jquery 如何从webservice用json对象加载jqgrid?
我有一个webservice和jqgrid,我想用数据库的表加载jqgridJquery 如何从webservice用json对象加载jqgrid?,jquery,web-services,jqgrid,Jquery,Web Services,Jqgrid,我有一个webservice和jqgrid,我想用数据库的表加载jqgrid 我已经编写了方法getdata() 如果创建类是必要的,请告诉我写什么 如果我的代码出错,请告诉我哪里出错 [网络方法] public string getdata() { SqlConnection con=new SqlConnection(ConfigurationManager.ConnectionStrings["connection"].ToString()); SqlCommand
getdata()
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"
},
});
});
$(文档).ready(函数(){
jQuery(“jqgriddemo”).jqGrid({
url:“http://localhost:62442/WebServices/MyWebService.asmx“+”/“+”获取数据“,
contentType:“应用程序/json;字符集=utf-8”,
数据类型:“json”,
colNames:['Id','First Name','Last Name'],
colModel:[
{name:'id',index:'id',width:20,stype:'text'},
{name:'FirstName',索引:'FirstName',宽度:150},
{name:'LastName',索引:'LastName',宽度:150},
],
rowNum:10,
sortname:'id',
有一次:是的,
行列表:[10,20,30],
mtype:“POST”,
寻呼机:“#寻呼机”,
viewrecords:是的,
排序器:“desc”,
标题:“第一个Jqgrid”,
serializeGridData:函数(postData){
返回JSON.stringify(postData);
},
jsonReader:{
根:“d.rows”,
页面:“d.page”,
总计:“d.total”,
记录:“d.records”,
重复项:false,
用户数据:“用户数据”
},
});
});
请告诉我一个更好的方法,或提供给我一个链接来解决这个问题