SIGN UP MEMBER LOGIN:    
ARTICLE

Use of JQGrid in ASP.NET using ASMX Web Services

Posted by Rachana BG Articles | ASP.NET Programming October 03, 2011
Here I will use a JQGrid in ASP.NET Using ASMX Web Services (Paging,Sorting,Add/Edit/Del Functions).
Reader Level:
Download Files:
 

Here I will use a JQGrid in ASP.NET Using ASMX Web Services (Paging,Sorting,Add/Edit/Del Functions).

The grid is a Ajax-enabled JavaScript control that provides a solution for representing tabular data on the web. Since the grid is a client-side solution and loading data dynamically through Ajax callbacks, it can be integrated with any server side technology.

I found that many are trying to use JQgrid with ASP.NET. Even I tried to implement JQgrid with basic functionalities like paging, sorting, editing row, adding row, deleting row by searching in Google.

Finally I created one working example. So I thought I'd share it, thinking that it may be useful to someone.

Here I am not explaining from the scratch. There are many sources for JQgrid starters (You can get information about which plugins you need to refer to use  JQgrid, basic examples and demos here http://www.trirand.com/blog/jqgrid/jqgrid.html).

I would like to mention some important things which I found.

I have attached my code.

I have a Table in my database called 'Person' with the structure as below

Column Name

DataType

 

PID

int

Primary Key

FirstName

Nvarchar

 

LastNAme

Nvarchar

 

To run the project create the Person table as above and give your DB connection string.

  1. url: '/WebService.asmx/GetListOfPersons1': This method calls to load data to the grid.
  2. editurl: '/WebService.asmx/EditRow':This method calls while adding new row,Updating the row and deleting the row.
  3. Following setting for Add/Edit/Del operations.

    • To post the data to server as object ,have to set content type to "application/json" .
    • While deleting row ,grid posts only grid rowid and oper variables.

To a delete row at server side we need some column values, for example the primary key of the table. To achieve that this setting should be set for the delete operation.

onclickSubmit: function (eparams) {

                    var retarr = {};
                    var sr = jQuery("#contactsList").getGridParam('selrow');
                    rowdata = jQuery("#contactsList").getRowData(sr);
                    retarr = { PID: rowdata.PID};

jQuery.extend(jQuery.jgrid.edit, {

                closeAfterEdit: true,
                closeAfterAdd: true,
               
                ajaxEditOptions: { contentType: "application/json" },
                serializeEditData: function (postData) {
                    var postdata = { 'data': postData };
                    return JSON.stringify(postdata); ;
                }
            });
            jQuery.extend(jQuery.jgrid.del, {
                ajaxDelOptions: { contentType: "application/json" },
              
                onclickSubmit: function (eparams) {
                    var retarr = {};
                    var sr = jQuery("#contactsList").getGridParam('selrow');
                    rowdata = jQuery("#contactsList").getRowData(sr);
                    retarr = { PID: rowdata.PID};
                    
                    return retarr;
                },
                serializeDelData: function (data) {
                    var postData = { 'data': data };
                    return JSON.stringify(postData);
                } 

Login to add your contents and source code to this article
share this article :
post comment
 
Become a Sponsor
PREMIUM SPONSORS
  • Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
    Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites - Click Here!
Nevron Gauge for SharePoint
Become a Sponsor