title: JQGrid How to prepopulate before adding new Record
body: <p>I am adding new data to jqgrid. The data is related to a customer, so new record must contain the customer id. Hence I want the popup form for adding record should come with customer code pre populated (readonly) . Customer Code is available in a dropdown list. 
  I tried the following - added a custom button with a custom function AddRow (This is a borrowed code from Internet ). Inside the function I am using setColProp to set the CustomerId into the field. However, nothinng happens. Not even the popup appears.
  Is there any easier way of doing the same thing?</p>
  
  <pre><code>        jQuery("#list").jqGrid({
                  url: '&lt;%= ResolveClientUrl("~/service/OfficeData.asmx/GetDealer_SMS") %&gt;',
                  editurl: '&lt;%= ResolveClientUrl("~/service/OfficeData.asmx/InsertDealer_SMS") %&gt;',
                  datatype: "json",
                  mtype: 'POST',
                  ajaxGridOptions: { contentType: 'application/json; charset=utf-8' },
                  ajaxEditOptions: { ContentType: 'application/json; charset=utf-8', dataType: 'json' },
                  serializeGridData: function (postData) {
                      //alert("Call");
                      if (postData.DealerCode === undefined) { postData.DealerCode = DealerCode; }
                      else {
                          postData.DealerCode = DealerCode;
                      }
                      return JSON.stringify(postData);
                  },
                  jsonReader: { repeatitems: false, root: "d.rows", page: "d.page", total: "d.total", records: "d.records" },
                  colNames: ['ID', 'DealerCode', 'Name', 'Designation', 'Address', 'EMail', 'Mobile'],
                  colModel: [{ name: 'id', index: 'id', width: 10, align: 'left', editable: true, hidden: true,
                      editrules: { required: false },
                      editoptions: {
                          dataInit: function (element) {
                              $(element).attr("readonly", "readonly");
                          }
                      }
                  },
                  { name: 'DealerCode', index: 'DealerCode', width: 60, align: 'left', editable: true,
                      editrules: { required: true },
                      editoptions: {
                          dataInit: function (element) {
                              $(element).attr("readonly", "readonly");
                          }
                      }
                  },
                  { name: 'RecpName', index: 'RecpName', width: 150, align: 'left', editable: true,
                      editrules: { required: true }, editoptions: { size: 30, maxlength: 150 }
                  },
                  { name: 'RecpDesignation', index: 'RecpDesignation', width: 100, align: 'left', editable: true,
                      editrules: { required: true }, editoptions: { size: 30, maxlength: 150 }
                  },
                  { name: 'RecpAddress', index: 'RecpAddress', width: 250, align: 'left', editable: true,
                      editrules: { required: true }, editoptions: { size: 30, maxlength: 400 }
                  },
                  { name: 'RecpEMail', index: 'RecpEMail', width: 150, align: 'left', editable: true,
                      editrules: { required: true }, editoptions: { size: 30, maxlength: 150 }
                  },
                  { name: 'RecpMobile', index: 'RecpMobile', width: 100, align: 'left', editable: true,
                      editrules: { required: true }, editoptions: { size: 30, maxlength: 30 }
                  }],
                  loadError: function (jqXHR, textStatus, errorThrown) {
                      alert('Error while loading -' + errorThrown);
                  },
                  pager: jQuery('#pager'),
                  rowNum: 20,
                  rowList: [10, 20, 50],
                  sortname: 'RecpName',
                  sortorder: "asc",
                  viewrecords: true,
                  imgpath: '/scripts/themes/steel/images',
                  caption: 'Dealer Recepient Details'
              }).jqGrid('navGrid', '#pager', { edit: false, add: false, del: false, search: false })
  
              .navButtonAdd('#pager',
      { caption: "Add",
      buttonicon: "ui-icon-plus",
   onClickButton: addRow,
  
    title: "",
    cursor: "pointer"
   }
   )
        .navButtonAdd('#pager',
          { caption: "Edit",
        buttonicon: "ui-icon-pencil",
       onClickButton: editRow,
       position: "last",
      title: "",
      cursor: "pointer"
      }
     ).navButtonAdd('#pager',
     { caption: "Delete",
     buttonicon: "ui-icon-trash",
     onClickButton: deleteRow,
     position: "last",
     title: "",
     cursor: "pointer"
    }
    );
  
  
              function addRow() {
                  alert(DealerCode);
                  $("#grid").jqGrid('setColProp', 'DealerCode', { editoptions: { readonly: true, size: 10, value: DealerCode} });
  
  
                  $('#grid').jqGrid('editGridRow','new',
  { url: '&lt;%= ResolveClientUrl("~/service/OfficeData.asmx/InsertDealer_SMS") %&gt;',
  editData: {},
  serializeEditData: function(data){
  data.id = 0;
  return $.param(data);
  },
  recreateForm: true,
  beforeShowForm: function(form) {
  $('#pData').hide();
  $('#nData').hide();
  
  },
  beforeInitData: function(form) {},
  closeAfterAdd: true,
  reloadAfterSubmit:true,
  afterSubmit : function(response, postdata)
  {
  var result = eval('(' + response.responseText + ')');
  var errors = "";
  if (result.success == false) {
  for (var i = 0; i &lt; result.message.length; i++) {
  errors += result.message[i] + "&lt;br/&gt;";
  }
  } else {
  $('#msgbox').text('Entry has been added successfully');
  $('#msgbox').dialog(
  { title: 'Success',
      modal: true,
  buttons: {"Ok": function() {
  $(this).dialog("close");}
  }
  });
  }
  // only used for adding new records
  var newId = null;
  return [result.success, errors, newId];
  }
  });
  
  
  } // end of addRow
  </code></pre>
  
  <p>Thanks in advance</p>