前端:
$("#UsersGrid").jqGrid({
url: "jqGridHandler.ashx",
mtype: 'post',
datatype: 'json',
height: 250,
colNames: ['CardNumber', 'CardType', 'CardGrade', 'CanUseMoney', 'MemberName'],
colModel: [
{ name: 'CardNumber', index: 'CardNumber', width: 150, search: true,
searchoptions: { sopt: ['eq']}},
{ name: 'CardType', width: 150},
{ name: 'CardGrade', width: 150 },
{ name: 'CanUseMoney', width: 150 },
{ name: 'MemberName', width: 150, search: true,
searchoptions: { sopt: ['eq']} }
],
rowNum: 10,
rowList: [10, 20, 30],
sortname: 'CardNumber',
viewrecords: true,
sortorder: 'asc',
caption: 'card',
pager: $("#pager")
}).navGrid('#pager',
{ search: true, edit: false, add: false, del: false, searchtext: "search" });
jqGridHandler.ashx:
HttpRequest request = context.Request;
string _searchsrt = request["searchString"];
我想在“jqGridHandler.ashx”中获取searchString
,但我发现它是“”
怎么做?谁能帮我吗? TKS!
答案 0 :(得分:2)
您可以使用HttpRequest
获取发送jqGrid的参数。代码可以是以下内容:
public class jqGridHandler: IHttpHandler {
public void ProcessRequest(HttpContext context) {
HttpRequest request = context.Request;
HttpResponse response = context.Response;
// get parameters sent from jqGrid
string numberOfRows = request["rows"];
string pageIndex = request["page"];
string sortColumnName = request["sidx"];
string sortOrderBy = request["sord"];
string isSearch = request["_search"];
string searchField = request["searchField"];
string searchString = request["searchString"];
string searchOper = request["searchOper"];
// construct the JSON data based on the
string output = BuildJQGridResults (
Convert.ToInt32 (numberOfRows),
Convert.ToInt32 (pageIndex),
Convert.ToInt32 (totalRecords),
isSearch!= null && String.Compare (isSearch, "true",
StringComparison.Ordinal) == 0,
searchField,
searchString,
searchOper
);
response.ContentType = "application/json";
response.Write (output);
}
仅当用户使用single searching dialog(您未设置searchString
选项时,才会设置参数searchField
,searchOper
和multipleSearch: true
,这一点很重要)。对于Advanced Searching dialog,将使用参数filters。如果用户未使用任何搜索对话框,相应的参数(searchString
,searchField
,searchOper
或filters
)将为null
。