2012-03-20 58 views
0

前端:如何獲得搜索字符串在ASP.NET中使用的jqGrid

$("#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"]; 

我想獲得searchString在 「jqGridHandler.ashx」,但我發現它是「」 該怎麼辦?誰能幫我嗎? TKS!

回答

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這一點很重要的參數searchStringsearchFieldsearchOper將只設置(你沒有設置multipleSearch: true選項)。對於Advanced Searching dialog,將使用參數filters。如果用戶未使用任何搜索對話框,則相應參數(searchString,searchField,searchOperfilters)將爲null

相關問題