<script type="text/javascript" charset="gb2132">
$(document).ready(function () {
jQuery("#list").jqGrid({
url: 'ashx/BaseBranchManager.ashx?type=GetBaseBranch',
mtype: 'POST',
datatype: "json",
height: 'auto',
width: 500,
colNames: ['編號', '名稱'],
colModel: [
{ name: 'BranchID', index: 'BranchID', width: '50' },
{ name: 'BranchDesc', index: 'BranchDesc' }
],
viewrecords: true,
rowNum: 10,
rowList: [10, 20, 30],
sortname: 'CommentID',
jsonReader: {
root: "rows",
page: "pageindex",
total: "pagecount",
records: "total",
repeatitems: false,
id: "0"
},
loadonce: true,
sortname: 'id',
viewrecords: true,
pager: "#pager",
caption: "客戶列表",
sortorder: "desc",
hidegrid: false,
onSelectRow: function (ids) {
jQuery("#order").setGridParam({
url: "ashx/Handler.ashx?BranchId=" + ids, page: 1
}).trigger("reloadGrid");
alert(ids);
}
});
jQuery("#list").jqGrid('navGrid', '#pager', { edit: false, add: false, del: false });
jQuery("#order").jqGrid({
url: '',
mtype: 'POST',
datatype: "json",
height: 'auto',
width: 500,
colNames: ['編號'],
colModel: [
{ name: 'BranchID', index: 'BranchID', width: '50' }
],
viewrecords: true,
rowNum: 10,
rowList: [10, 20, 30],
sortname: 'CommentID',
jsonReader: {
root: "rows",
page: "pageindex",
total: "pagecount",
records: "total",
repeatitems: false,
id: "0"
},
loadonce: true,
sortname: 'id',
viewrecords: true,
pager: "#orderppage",
caption: "客戶列表",
sortorder: "desc",
hidegrid: false
});
jQuery("#order").jqGrid('navGrid', '#orderppage', { edit: false, add: false, del: false });
});
</script>
上面是我一個主從表的代碼,也就是點擊一個列后,另一個表根據(jù)ID綁定數(shù)據(jù)!但是出現(xiàn)這樣的情況,就是說,第一次點擊的時候,就會進入BaseBranchManager.ashx文件中,但是第二次再點擊就不可以!BaseBranchManager.ashx代碼如下:
public void ProcessRequest (HttpContext context) {
context.Response.ContentType = "application/json";
string resultJson = "";
if (context.Request["type"] == "GetBaseBranch")
{
resultJson = GetBaseBranch();
}
if (context.Request["type"] == "GetOrderCar")
{
resultJson = SelectOrderdtByBanchId(context.Request["BranchId"].ToString());
}
context.Response.Write(resultJson);
}
private static string GetBaseBranch()
{
WcfService.ProductsServiceClient pr = new WcfService.ProductsServiceClient();
DataTable dt = pr.GetBaseBranch();
// 每頁顯示記錄數(shù)
int pageSize = 10;
// 記錄總數(shù)
int rowCount = dt.Rows.Count;
// 總頁數(shù)
int pageCount = rowCount % pageSize == 0 ? rowCount / pageSize : rowCount / pageSize + 1;
var resultObj = new DataResult
{
// 總頁數(shù)
PageCount = pageCount,
// 當前頁
PageIndex = 1,
// 總記錄數(shù)
Total = rowCount,
// 數(shù)據(jù)
Data = dt
};
string resultJson = JsonHelper.Serialize(resultObj);
return resultJson;
}
試過用其他ASP頁面來實現(xiàn),但是如果我用?Response.End()的話,就第二次不進來執(zhí)行方法,不用?Response.End()的話,又不顯示數(shù)據(jù)!請問這是什么回事呢!
用過jquery jqgrid的幫忙看下這個問題。。。。
萬千封印
2018-12-06 17:54:10