Click here to Skip to main content
15,888,610 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello friends,

I am using navGrid feature of jqGrid to add record to database.

My question is: What is the correct way to call server side function to save record to database. I am using ajax fucntion to save record. I am able to call the ajax function and then server side code.

How to pass return value back to jqgrid. I am getting error: "error Status: 'Not Found'. Error code: 404"

My code is:

C#
jQuery("#list").jqGrid({
                   datatype: "jsonstring",
                   contentType: "application/json; charset=utf-8",

..........
C#
}).navGrid('#pager',
       {add:true,edit:true,del:true,search:true,refresh:true}, // which buttons to show?
       {editCaption: 'Update Environment', beforeSubmit: validateEditData, afterSubmit: processEdit },         // edit options
       {addCaption: 'New Environment', onclickSubmit: processAdd },  // add options
       {delCaption: 'Delete Row', beforeSubmit: validateDeleteData, afterSubmit: processDelete}          // delete options
   );;



I am calling my ajax function in "processAdd" function like this:
C#
$.ajax({
        url: 'Environments.aspx/AddNewEnvironment',
        data: Environment,
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        type: "POST",
        success: function (data) {
.....
.....
return [dat.result, dat.message];
        },





Can any one tell me "How to add record using navGrid functionality? step by step?"
Regards
Posted
Updated 2-Dec-11 5:34am
v2

1 solution

Hi,

You need to rebind JQGrid like:

you can set your Page and Method name for getting data for example
JavaScript
url: 'Environments.aspx/GetEnvironmentList'


Following is whole code for JQGrid
C#
jQuery(document).ready(function () {
       jQuery("#list").jqGrid({
           url: '@Url.Action("JQGridGetGridData", "TabMaster")',
           datatype: 'json',
           mtype: 'GET',
           colNames: ['col ID', 'First Name', 'Last Name', ''],
           colModel: [
                     { name: 'colID', index: 'colID', width: 100, align: 'left', searchoptions: { sopt: ['eq', 'ne', 'cn']} },
                     { name: 'FirstName', index: 'FirstName', width: 150, align: 'left', editable: true, editrules: { required: true} },
                     { name: 'LastName', index: 'LastName', width: 150, align: 'left', editable: true },
                     { name: 'Edit', index: 'Edit', width: 70, align: 'center', editable: false, formatter: editFmatter, unformat: unformatEdit }
                   ],
           pager: jQuery('#pager'),
           hidegrid: false,
           rowNum: 100,
           rowList: [10, 50, 100, 150],
           sortname: 'colID',
           sortorder: "asc",
           viewrecords: true,
           multiselect: false,
           imgpath: '@Url.Content("~/Scripts/themes/steel/images")',
           caption: 'Tab Master Information',
           editurl: '@Url.Action("JQGridEdit", "TabMaster")'
       }).navGrid('#pager', { edit: false, add: false, del: false, search: false, refresh: false });
   });


If you would like to more help for that please feel free to ask me.

Thanks,
Imdadhusen
 
Share this answer
 
Comments
jayasankar16 21-Nov-13 0:44am    
Hi i got one requirement, it's like once the records load from database to jqgrid, then i'm going for customized popup for adding record. once i add new records what ever i required then final save. if click on final save all the records should get saved in database. we have to do only client side. can any one give some code or some clues to proceed furthur
Member 2766194 15-Apr-14 13:13pm    
My Grid navigation icons are not visible..images missing for the navgrid.help me

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900