zoukankan      html  css  js  c++  java
  • JQGrid+Nhibernate+Webservice+Linq

    先上效果图:

    image 

    前台代码(jqgridtest.aspx):

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="jqgridtest.aspx.cs" Inherits="WebNhibernate4.jqgridtest" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
        <link id="uiThemes" rel="stylesheet" type="text/css" media="screen" href="Pub/jqgrid/css/ui-lightness/jquery-ui-1.8.13.custom.css" />
        <link rel="stylesheet" type="text/css" media="screen" href="Pub/jqgrid/css/ui.jqgrid.css" />
        <script type="text/javascript" src="Pub/jqgrid/js/jquery-1.5.2.min.js"></script>
        <script src="Pub/jqgrid/js/i18n/grid.locale-cn.js" type="text/javascript"></script>
        <script src="Pub/jqgrid/js/jquery.jqGrid.min.js" type="text/javascript"></script>
        <script type="text/javascript">
            $(function () {
                jQuery("#list2").jqGrid({
                    url: 'JQGridService.asmx/JsonLinqData',
                    data: {},
                    datatype: 'json',
                    mtype: 'POST',
                    loadonce: true,
                    ajaxGridOptions: { contentType: 'application/json; charset=utf-8' },
                    serializeGridData: function (postData) {
                        return JSON.stringify(postData);
                    },
                    jsonReader: {
                        root: function (obj) {
                            var data = eval("(" + obj.d + ")");
                            return data.rows;
                        },
                        page: function (obj) {
                            var data = eval("(" + obj.d + ")");
                            return data.page;
                        },
                        total: function (obj) {
                            var data = eval("(" + obj.d + ")");
                            return data.total;
                        },
                        records: function (obj) {
                            var data = eval("(" + obj.d + ")");
                            return data.records;
                        }
                    },
                    colNames: ['Inv No', 'firstname', 'lastname'],
                    colModel: [
       		            { name: 'CustomerId', index: 'CustomerId',  55 },
       		            { name: 'Firstname', index: 'Firstname',  90 },
       		            { name: 'Lastname', index: 'Lastname',  100 }
       	            ],
                    rowNum: 10,
                     600,
                    rowList: [10, 20, 30],
                    pager: '#pager2',
                    sortname: 'Firstname',
                    viewrecords: true,
                    sortorder: "asc",
                    caption: "JSON Example"
                });
                jQuery("#list2").jqGrid('navGrid', '#pager2', { edit: false, add: false, del: false });
            });
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <table id="list2" style="600px;"></table> <div id="pager2"></div>
        </div>
        </form>
    </body>
    </html>
    
    web服务代码(JQGridService.asmx):
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Services;
    using NHibernate;
    using Newtonsoft.Json;
    using Newtonsoft.Json.Converters;
    
    namespace WebNhibernate4
    {
        /// <summary>
        /// JQGridService 的摘要说明
        /// </summary>
        [WebService(Namespace = "http://tempuri.org/")]
        [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
        [System.ComponentModel.ToolboxItem(false)]
        // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。
        [System.Web.Script.Services.ScriptService]
        public class JQGridService : System.Web.Services.WebService
        {
    
            [WebMethod(EnableSession = true)]
            public string JsonLinqData()
            {
    
                NHibernateHelper _helper = new NHibernateHelper();
                ISession _session = _helper.GetSession();
                ICriteria criteria = _session.CreateCriteria(typeof(Customer));
                criteria.SetMaxResults(25);
                IList<Customer> Customer = criteria.List<Customer>();
    
                var page = 2;
                var jsonData = new
                {
                    page = page,
                    total = 12,
                    records = 25,
                    rows = (
                            from bl in Customer
                            select new
                            {
                                id = bl.CustomerId,
                                cell = new string[] {
                                    bl.CustomerId.ToString(),
                                    bl.Firstname.ToString(),
                                    bl.Lastname.ToString()}
                            }).ToArray()
                };
    
                return JsonConvert.SerializeObject(jsonData);
    
            }
    
        }
    }
  • 相关阅读:
    ORACLE 递归查询(转)
    J2EE框架(TomcatStrutsHibernateSpringAjax(dojo))开发步骤
    java.lang.NoClassDefFoundError: net/sf/cglib/proxy/CallbackFilter 异常解决办法
    Oracle WebCenter 11g 快速开发指南翻译(二)
    keytool密钥和证书管理工具使用详解(整理)
    内存溢出异常解决方案总结
    Spring+JDBC组合开发
    Oracle WebCenter 11g 快速开发指南翻译(三)
    SQL SERVER 2005 数据挖掘与商业智能完全解决方案学习笔记(一)
    MyEclipse 打开Struts配置文件时出错的终级解决办法
  • 原文地址:https://www.cnblogs.com/jason819/p/3181665.html
Copyright © 2011-2022 走看看