没有使用c#asp.net绑定到我的JQGrid的数据 [英] no data binding to my JQGrid using c# asp.net
本文介绍了没有使用c#asp.net绑定到我的JQGrid的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您使用json和词典实现了jquery网格。
我收到了Request.InputStream错误。我总是得到空值。
如果我传递静态输入方法GetData它显示空网格。
Hi implemented jquery grid using json and dictionaries.
I am getting error with Request.InputStream. i am always getting null value.
If i pass static inputs method "GetData" it showing empty grid.
public class EmpDetails
{
public int id;
public string[] cell;
}
public class JsonEmployeeData
{
public int page;
public int total;
public int records;
public EmpDetails[] rows;
}
public partial class NewImpUsingJson : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Request.QueryString["method"] == "GetData")
{
Request.InputStream.Position = 0;
StreamReader ipStRdr = new StreamReader(Request.InputStream);
string json = ipStRdr.ReadToEnd();
JavaScriptSerializer jser = new JavaScriptSerializer();
Dictionary<string, string> dict = jser.Deserialize<Dictionary<string, string>>(json);
//NewImpUsingJson.GetData(1,10,1,"ASC");
NewImpUsingJson.GetData(int.Parse(dict["page"].ToString()), int.Parse(dict["rows"].ToString()), int.Parse(dict["_search"].ToString()), dict["sord"].ToString());
Response.End();
}
}
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public static JsonEmployeeData GetData(int page, int rows, int _search, string sord)
{
//int startindex = (page - 1) * pagesize;
//int endindex = page * pagesize;
string queryString = "SELECT Row_Number() over (order by EmployeeId ASC) as rowID, EmployeeId,EmployeeName,ContactNumber FROM (Select ROW_NUMBER() OVER (ORDER BY EmployeeId ASC) AS ROWID," +
"EmployeeId,EmployeeName,ContactNumber FROM EmployeeJtable) AS a"; SqlConnection connection = new SqlConnection(@"Data Source=HYD-NPULIVARTHY;Initial Catalog=test2;Integrated Security=True");
connection.Open();
DataTable dt = new DataTable();
SqlDataAdapter adapter = new SqlDataAdapter(queryString, connection);
var tRows = adapter.Fill(dt);
JsonEmployeeData result = new JsonEmployeeData();
List<EmpDetails> rowsadded = new List<EmpDetails>();
int index=1;
foreach (DataRow dtRow in dt.Rows)
{
EmpDetails newrow = new EmpDetails();
newrow.id = index++;
newrow.cell = new string[3];
newrow.cell[0] = dtRow[1].ToString();
newrow.cell[1] = dtRow[2].ToString();
newrow.cell[2] = dtRow[3].ToString();
rowsadded.Add(newrow);
}
result.rows = rowsadded.ToArray();
result.page = page;
result.total = ((rowsadded.Count + rows - 1) / tRows);
result.records = rowsadded.Count;
return result;
}
}
和我的脚本代码是
and my script code is
<script type="text/javascript">
$(document).ready(function () {
var sPage="NewImpUsingJson.aspx"
jQuery("#Grid1").jqGrid({
url: sPage + '?method=GetData',
datatype: 'json',
mtype: 'GET',
colNames: ['id','EmployeeId', 'EmployeeName', 'ContactNumber'],
colModel: [
{ name: 'id', index: 'id', width: 60, search: false },
{ name: 'EmployeeId', index: 'EmployeeId', width: 90, align: 'center', sorttype: 'EmployeeId'},
{ name: 'EmployeeName', index: 'EmployeeName', width: 105, align: 'right' },
{ name: 'ContactNumber', index: 'ContactNumber', width: 95, align: 'left' }
],
pager: '#pager',
sortname: 'EmployeeId',
viewrecoreds: true,
serializeGridData: function(data)
{
// return $.toJSON(data); /// done to override default serialization
return JSON.stringify(data);
},
jsonReader: { repeatitems: false, root: "rows", page: "page", total: "total", records: "records" }
});
jQuery("#Grid1").jqGrid('navGrid', '#Pager', { edit: false, add: false, del: false }, null, null, true, { multipleSearch: true });
var height = $(window).height();
});
</script>
请任何帮助实施显示使用SQL Server 2008数据在JQGrid中的数据。
please any one help to implement displaying data in JQGrid using SQL Server 2008 data.
推荐答案
(document).ready(function(){
var sPage =NewImpUsingJson.aspx
jQuery(#Grid1)。jqGrid({
url:sPage +'?method = GetData',
datatype:'json',
mtype:'GET',
colNames:['id','EmployeeId','EmployeeName','ContactNumber'],
colModel:[
{name:'id',index:'id',width:60, search:false},
{name:'EmployeeId',index:'EmployeeId',width:90,align:'center',sorttype:'EmployeeId'},
{name:'EmployeeName', index:'EmployeeName',width:105,align:'right'},
{name:'ContactNumber',index:'ContactNumber',width:95,align:'left'}
],
寻呼机:'#pager',
sortname:'EmployeeId',
viewrecoreds:true,
serializeGridData:function(data)
{
// return
(document).ready(function () { var sPage="NewImpUsingJson.aspx" jQuery("#Grid1").jqGrid({ url: sPage + '?method=GetData', datatype: 'json', mtype: 'GET', colNames: ['id','EmployeeId', 'EmployeeName', 'ContactNumber'], colModel: [ { name: 'id', index: 'id', width: 60, search: false }, { name: 'EmployeeId', index: 'EmployeeId', width: 90, align: 'center', sorttype: 'EmployeeId'}, { name: 'EmployeeName', index: 'EmployeeName', width: 105, align: 'right' }, { name: 'ContactNumber', index: 'ContactNumber', width: 95, align: 'left' } ], pager: '#pager', sortname: 'EmployeeId', viewrecoreds: true, serializeGridData: function(data) { // return
.toJSON(data); ///完成覆盖默认序列化
返回JSON.stringify(data);
},
jsonReader:{repeatitems:false,root:rows,page:page,total:total,records:records}
});
jQuery(#Grid1)。jqGrid('navGrid','#Pager',{edit:false,add:false,del:false},null,null,true,{multipleSearch:true});
var height =
.toJSON(data); /// done to override default serialization return JSON.stringify(data); }, jsonReader: { repeatitems: false, root: "rows", page: "page", total: "total", records: "records" } }); jQuery("#Grid1").jqGrid('navGrid', '#Pager', { edit: false, add: false, del: false }, null, null, true, { multipleSearch: true }); var height =
(window).height();
});
< / script>
(window).height(); }); </script>
请任何帮助实施显示使用SQL Server 2008数据在JQGrid中的数据。
please any one help to implement displaying data in JQGrid using SQL Server 2008 data.
这篇关于没有使用c#asp.net绑定到我的JQGrid的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文