title: passing data from jqGrid to webmethod
body: <p>This is my jqGrid calling web method</p>
  
  <pre><code>$(document).ready(function () {
      jQuery("#prodgrid").jqGrid({
          url: 'product_brow.aspx/ProdGrid',
          postData: {
              ddlproductstatus: function() {
                  return  $("#&lt;%=ddlProductStatus.ClientID%&gt;").val();
              },
              ddlproducttype: function() {
                  return  $("#&lt;%=ddlProductType.ClientID%&gt;").val();
              }, 
              txtkeywordsearch: function() {
                  return  $("#&lt;%=txtKeywordSearch.ClientID%&gt;").val();
              },
              hdnMerchantId: function() {
                  return  $("#&lt;%=hdnmerchantId.ClientID%&gt;").val();
              }
          },
          mtype: 'POST',
          serializeEditData: function (postData) {
              return JSON.stringify(postData);
          } ,
          colNames: ['Code', 'Title', 'Price', 'Product Group', 'Edit', 'Status'],
          colModel: [
              { name: 'Code', index: 'Code', width: 15, align: 'center' },
              { name: 'Title', index: 'Title', width: 40, align: 'center' },
              { name: 'Price', index: 'Price', width: 55 },
              { name: 'Product Group', index: 'Product Group', width: 55 },
              { name: 'Edit', index: 'Edit', width: 40 },
              { name: 'Status', index: 'Status', width: 40}],
          pager: '#prod_pager',
          rowList: [10, 20, 30],
          sortname: 'Code',
          sortorder: 'desc',
          rowNum: 10,
          loadtext: "Loading....",
          shrinkToFit: true,
          multiselect: true,
          emptyrecords: "No records to view",
          width: x - 40,
          height: 230,
          rownumbers: true,
          subGrid: true,
          caption: 'Products'
          // editurl: 'Departments.aspx' 
      });
      jQuery("#prodgrid").jqGrid('navGrid', '#prod_pager',
          { edit: false, add: false, del: true, excel: true, search: false });
  });
  </code></pre>
  
  <p>as you can see im trying to pass data from here to web method with parameters like this</p>
  
  <pre><code>[WebMethod]
  public static string ProdDetails(string ddlproductstatus,
                                   string ddlproducttype,
                                   string txtkeywordsearch,
                                   string hdnMerchantId)
  {
      StringBuilder sbReturnJson = new StringBuilder();
      string strReturnJson = string.Empty;
      StringBuilder sbCell = new StringBuilder();
  
      try
      {
          string sort = HttpContext.Current.Request.Form["sidx"].ToString();
          string strSortDerection = HttpContext.Current.Request.Form["sord"].ToString();
          int iPage = Convert.ToInt32(HttpContext.Current.Request.Form["page"]);//get the requested page
          string strLimit = HttpContext.Current.Request.Form["rows"].ToString(); // get how many rows we want to have into the grid
          string strStart = Convert.ToString(int.Parse(strLimit) * (iPage - 1));
          string strEnd = Convert.ToString(int.Parse(strStart) + int.Parse(strLimit));
  
          string pageNo = string.Empty;
          ProductDal oProductDal = new ProductDal();
  
          // bind data to gridview
  
          System.Data.DataTable oDataTable;
  
          if (txtkeywordsearch.Trim().Length == 0)
          {
              oDataTable = oProductDal.GetAllProductDtToDisplayTest(Convert.ToInt32(hdnMerchantId), ddlproducttype,
                  ddlproductstatus, iPage, Convert.ToInt32(strLimit));
          }
          else
          {
              oDataTable = oProductDal.GetAllProductDtToDisplayBySearchStringTest(Convert.ToInt32(hdnMerchantId), ddlproducttype,
                ddlproductstatus, txtkeywordsearch.Trim(), iPage, Convert.ToInt32(strLimit));
          }
  
          // keep values in session to use in product detail page to retrieve records.
          //Session["ProductType"] = ddlproducttype;
        //  Session["ProductStatus"] = ddlproductstatus;
  
          if (txtkeywordsearch.Trim().Length != 0)
          {
             // Session["SearchKeyword"] = txtkeywordsearch;
          }
  
  
          //  hlnkExportToExcel.Visible = false;
  
          // calculate the total number of records.
          int totalRows = 0;
  
          if (txtkeywordsearch.Trim().Length == 0)
          {
              totalRows = oProductDal.CountAllProductDtToDisplay(Convert.ToInt32(hdnMerchantId), ddlproducttype,
                      ddlproductstatus);
          }
  
          else
          {
              totalRows = oProductDal.CountAllProductDtToDisplayBySearchString(Convert.ToInt32(hdnMerchantId), ddlproducttype,
                      ddlproductstatus, txtkeywordsearch.Trim());
          }
  
          //if (!IsPostBack)
          //{
          //    gvProductBrow.PageIndex = _currentPageNumber;
          //}
  
  
          var count = oDataTable.Rows.Count;
  
          sbReturnJson.Append("{\"page\":\"" + iPage + "\",\"records\":\"" + count + "\",\"rows\":[");
          foreach (DataRow row in oDataTable.Rows)
          {
              // int depid = Convert.ToInt32(row[1].ToString());
              // var Editbutton = "&lt;img Class='GridEdit' onclick='showjQueryDialog(" + depid + ");' src='Images/edit.jpeg'&gt;&lt;/img&gt;";
              //&lt;a href='#' Class='GridEdit' onclick='showjQueryDialog(" + depid + ");'&gt;Edit&lt;/a&gt;
              string code = (row[1].ToString());
              string title = (row[4].ToString());
              string price = (row[7].ToString());
              string product_group = (row[5].ToString());
              string edit = (row[0].ToString());
              string status = (row[2].ToString());
  
              sbCell.Append("{\"cell\":[\"" + code + "\",\"" + title + "\",\"" + price + "\",\"" + product_group + "\",\"" + edit + "\",\"" + status + "\"]}");
              sbCell.Append(",");
          }
  
         // lblNoOfRows.Text = totalRows + " record(s) found";
  
          sbReturnJson.Append(sbCell.ToString().TrimEnd(','));
          double dCount = Math.Ceiling(Convert.ToDouble(count / int.Parse(strLimit)));
          int iCount = int.Parse(dCount.ToString()) + 1;
          sbReturnJson.Append("],\"total\":\"" + iCount + "\"}");
  
          //lblTopPageNo.Text = (gvProductBrow.PageIndex + 1) + "/" + CalculateTotalPages(totalRows);
          //lblBottomPageNo.Text = (gvProductBrow.PageIndex + 1) + "/" + CalculateTotalPages(totalRows);
          //ViewState["NoOfPages"] = CalculateTotalPages(totalRows);
  
      }
      catch (Exception ex)
      {
          ExceptionLogger.LogException(ex);
          //lblErrorMessage.Text += Resources.Resource.Product_errMsgLoadProduct;
          return "Error";
      }
      return sbReturnJson.ToString();  
  }
  </code></pre>
  
  <p>my web method is expecting 4 parameters which i am trying to pass using postData but since i am a newbi i dont know how to post data to tht web method from my jqGrid. Need help got stuck with this for around 5 hrs</p>
  
  <p>can you also help with sending the page,sidx,sort from jqgrid to web method</p>