front-end:
$("#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"];
I would like to get searchString
in "jqGridHandler.ashx", but I found it is ""
how to do? can any one help me out? tks!
You can use HttpRequest
to get the parameters which send jqGrid. The code can be about the following:
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);
}
It's important that the parameters searchString
, searchField
and searchOper
will be set only if the user uses single searching dialog (you don't set multipleSearch: true
option). For the Advanced Searching dialog the parameter filters will be used. If the user don't used any searching dialog the corresponding parameters (searchString
, searchField
, searchOper
or filters
) will be null
.