jqgrid ashx

12 篇文章 0 订阅
2 篇文章 0 订阅

前台代码:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication2.WebForm1" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title></title>
    <link rel="stylesheet" type="text/css" media="screen" href="jqgrid_demo35/themes/redmond/jquery-ui-1.7.1.custom.css" />
    <link rel="stylesheet" type="text/css" media="screen" href="jqgrid_demo35/themes/ui.jqgrid.css" />

    <script src="jqgrid_demo35/js/jquery-1.7.2.min.js" type="text/javascript"></script>
    <script src="jqgrid_demo35/js/i18n/grid.locale-cn.js" type="text/javascript"></script>
    <script src="jqgrid_demo35/js/jquery.jqGrid.min.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(function () {
            jQuery("#list2").jqGrid({
                url: 'http://localhost:49348/Handler1.ashx',
                data: {},
                datatype: 'json',
                mtype: 'POST',
                loadonce: true,
                ajaxGridOptions: { contentType: 'application/json; charset=utf-8' },
                serializeGridData: function (postData) {
                    return JSON.stringify(postData);
                },
                jsonReader: {
                    root: "rows",
                    page: "page",
                    total: "total",
                    records: "records",
                    repeatitems: false
                },
                colNames: ['ID', 'UserName'],
                colModel: [
                    { name: 'ID', index: 'ID', width: 55 },
                    { name: 'UserName', index: 'Names', width: 90 }
                ],
                rowNum: 10,
                width: 600,
                rowList: [10, 20, 30],
                pager: '#pager2',
                sortname: 'name',
                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">
        <input type="button" value="重新加载" id="btnQuery" />
        <div>
            <table id="list2" style="width: 600px;"></table>
            <div id="pager2"></div>
        </div>
    </form>
</body>
</html>


Handler1.ashx文件代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Script.Serialization;

namespace WebApplication2
{
    /// <summary>
    /// Handler1 的摘要说明
    /// </summary>
    public class Handler1 : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            List<ChinaUser> list = new List<ChinaUser>(){new ChinaUser() { ID=1,UserName="Wujy"},
                new ChinaUser() { ID=2,UserName="踏浪帅"}
            };
            GridData model = new GridData();
            model.page = "1";
            model.records = "10";
            model.total = "10";
            model.rows = list;
            JavaScriptSerializer serializer = new JavaScriptSerializer();
            string Resul = serializer.Serialize(model);
            context.Response.Write(Resul);
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }

    public class ChinaUser
    {
        public int ID { set; get; }
        public string UserName { get; set; }
    }


    public class GridData
    {
        public string page { set; get; }
        public string total { get; set; }
        public string records { get; set; }
        public List<ChinaUser> rows { get; set; }
    }
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

lijun_xiao2009

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值