easyUI分页 asp.net java

easyui分页,首先我看了官网的示例,很简单,没什么用处,于是我在网上搜索相关的资料信息,看了很多,代码太乱,看的很烦躁,看最后还是得到了想要的东西。
我才发现其实easyui分页如此简单,现在我和大家分享一下成果,不在让后人在这上面浪费时间。 这里要说一下  java 也可以用主要是传递tatol 一下示例是asp.net


首先是前台
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="UserGroupManage.aspx.cs" Inherits="rightPage_sysManager_GroupManage" %>


<!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>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <script type="text/javascript" src="../../js/jquery-easyui1.3.2/jquery-1.8.0.min.js"></script>
    <script type="text/javascript" src="../../js/jquery-easyui1.3.2/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="../../js/jquery-easyui1.3.2/locale/easyui-lang-zh_CN.js"></script>
    <link href="../../js/jquery-easyui1.3.2/themes/icon.css" rel="stylesheet" type="text/css" />
    <link href="../../js/jquery-easyui1.3.2/themes/gray/easyui.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript">
       $(function(){  
            $('#tbuser').datagrid({   
                url: "../../code/UserGroupManage.ashx?iType=3&r="+Math.random(),  
                title: '用户组管理',  
                width: $("#main").width(),  
                height: $("#main").height(),  
                fitColumns: true,  
                nowrap:false,  

                pagination:true,  //重点

pageSize:10,

pageList:[10,20,30],

                singleSelect:true,

                idField:'cGroupName',
                frozenColumns:[[  
                    {field:'ck',checkbox:true},   
                ]],
                columns:[[
                    {field:'code',title:'编号',width:100,align:'center'},  
                    {field:'cGroupName',title:'组名',width:100,align:'center'},  
                    {field:'cDesc',title:'备注',width:100,align:'center'},
                    {field:'opt',title:'操作工作组',width:100,align:'center',
                        formatter:function(value,rec){  
                            return '<span style="color:red;cursor:pointer;"><a href="#" class="easyui-linkbutton" οnclick="editRow(\''+rec.cGroupName
+'\')">修改</a>  <a href="#" class="easyui-linkbutton" οnclick="deleteRow(\'' + rec.cGroupName + '\')">删除</a></span>';  
                        } 
                    },
                ]],  
                rowStyler:function(index,row,css){  
                    if (row.listprice>80){  
                        return 'background-color:#6293BB;color:#fff;font-weight:bold;';  
                    }  
                }     
               });
            });
    </script>
</head>
<body>
    <form id="form1" runat="server">
        <div style="margin:10px 0;"><a href="#" id="btnAddUserGroup" class="easyui-linkbutton" οnclick="openUser()">添加用户组</a></div>
        <table id="tbuser"  ></table>
    </form>
</body>
</html>

这个页面后台什么都没有

UserGroupManage.ashx
<%@ WebHandler Language="C#" Class="UserGroupManage" %>


using System;
using System.Web;
using System.Web.SessionState;
using System.Data;
using System.Text;


public class UserGroupManage : System.Web.IHttpHandler, IRequiresSessionState
{
    public void ProcessRequest(HttpContext context)
    {
        sysStructureHelp help = new sysStructureHelp();
 
        SendUi send = new SendUi();
        context.Response.ContentType = "text/plain";
             //Top pageSize
             int pageSize = Convert.ToInt32(Param("rows"));
            //页数
             int pageIndex = Convert.ToInt32(Param("page"));
             int pageCount = help.GetData("select  * from dbo.t_SA_UserGroupList where iUserType=2 ").Rows.Count;

            System.Data.DataTable dt = help.GetData("select top " + pageSize + " * from dbo.t_SA_UserGroupList  where iUserType=2 and id not in ( 

select top (" + pageSize + " * (" + pageIndex + "-1)) id from t_SA_UserGroupList where iUserType=2 order by id ) order by id");
            //System.Data.DataTable dt = help.GetData("select  * from dbo.t_SA_UserGroupList where iUserType=2 ");

        cresult = "{\"total\":" + pageCount + ",\"rows\":" + Dtb2Json(dt) + "}";//这一句是重点,只要把total(查询数据的总行数)传递到页面,分页也就算好了,其他easy给设置好了
        context.Response.Write(cresult);
    } 
    public bool IsReusable {
        get {
            return false;
        }
    }
    / <summary>
    / 将datatable转换为json  
    / </summary>
    / <param name="dtb">Dt</param>
    / <returns>JSON字符串</returns>
    private string Dtb2Json(System.Data.DataTable dtb)
    {
        //javascript序列化函数
        System.Web.Script.Serialization.JavaScriptSerializer jss = new System.Web.Script.Serialization.JavaScriptSerializer();
        //创建集合列表
        System.Collections.ArrayList dic = new System.Collections.ArrayList();
        //dic.Add(drows);
        //按照行来循环
        foreach (DataRow dr in dtb.Rows)
        {
 
            System.Collections.Generic.Dictionary<string, object> drow = new System.Collections.Generic.Dictionary<string, object>();
            //按照列来循环
            foreach (DataColumn dc in dtb.Columns)
            {


                drow.Add(dc.ColumnName, dr[dc.ColumnName]);                 
            }            
            dic.Add(drow);
 
        }
        //序列化  
        string cresult = jss.Serialize(dic);
        return cresult;
    }    
    private string Param(string Params)
    {
        return HttpContext.Current.Request.Params[Params];
    }
}


补充一下,如果你datatable转换为json 的方法不和我一样没事,只要cresult = 的格式是这样的就行

{"total":11,"rows":[{"ID":35,"cGroupName":"ww1","cDesc":"deferer","iHspPower":0,"iIdsPower":0,"iDbsPower":0,"iSvsPower":0,"iAppPower":0,"iLogPower":0,"iUserType":2,"cUserPermission":"101,101P1,101P2,101P3,","code":"8"},{"ID":37,"cGroupName":"123","cDesc":"4422","iHspPower":0,"iIdsPower":0,"iDbsPower":0,"iSvsPower":0,"iAppPower":0,"iLogPower":0,"iUserType":2,"cUserPermission":"101,101P1,101P2,","code":"10"}]}

最后一张图


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值