Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET JSON JQGrid
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:
 
jQuery("#list").jqGrid({
                   datatype: "jsonstring",
                   contentType: "application/json; charset=utf-8",
..........
}).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:
$.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 2-Dec-11 5:39am
Edited 2-Dec-11 6:34am
DaveAuld177.6K
v2

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Hi,
 
You need to rebind JQGrid like:
 
you can set your Page and Method name for getting data for example
url: 'Environments.aspx/GetEnvironmentList'
 
Following is whole code for JQGrid
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
  Permalink  
Comments
jayasankar16 at 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 at 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
0 OriginalGriff 539
1 Maciej Los 300
2 DamithSL 233
3 Sergey Alexandrovich Kryukov 209
4 BillWoodruff 200
0 OriginalGriff 7,168
1 Sergey Alexandrovich Kryukov 6,377
2 DamithSL 5,461
3 Manas Bhardwaj 4,876
4 Maciej Los 4,450


Advertise | Privacy | Mobile
Web03 | 2.8.1411023.1 | Last Updated 28 Dec 2011
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100