EasyUI DataGrid使用示例

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="EasyUIDemo.aspx.cs" Inherits="C_EasyUIDemo" %>





    
    EasyUI DataGrid示例
    
    
    
    
    
    
    


    
编号 用户名 用户密码 备注信息 账户余额 操作
用户名: 备注信息: 查询  新增  批量删除  导出选中
<%@ WebHandler Language="C#" Class="EasyUIHandler" %>

using System;
using System.Web;
using System.Collections.Generic;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.Data;
using System.Data.SqlClient;

public class EasyUIHandler : IHttpHandler {

    public void ProcessRequest(HttpContext context)
    {
        context.Response.ContentType = "text/plain";
        int pageIndex = MSCL.RequestHelper.GetInt("page", 0);  //当前页码
        int pageSize = MSCL.RequestHelper.GetInt("rows", 0);  //每页显示记录数
        string method = MSCL.RequestHelper.GetString("method");//前台传的标示值 

        string JsonStr = string.Empty;
        try
        {
            switch (method)
            {
                //查询数据
                case "query":
                    string dname = MSCL.RequestHelper.GetString("dname");
                    string delse = MSCL.RequestHelper.GetString("delse");

                    string sort = MSCL.RequestHelper.GetString("sort"); //排序字段名。
                    string order = MSCL.RequestHelper.GetString("order"); //排序方式
                    string where = string.Empty;
                    where += string.IsNullOrWhiteSpace(dname) ? "" : " And d_name like '%" + dname + "%' ";
                    where += string.IsNullOrWhiteSpace(delse) ? "" : " And d_else like '%" + delse + "%' ";
                    JsonStr = QueryData(pageIndex, pageSize, where, sort, order);
                    break;
                default:
                    break;
            }
        }
        catch (Exception ex)
        {
            throw;
        }
        context.Response.Write(JsonStr);
        context.Response.End();
    }

    #region 
    /// 
    /// 查询数据
    /// 
    /// 当前页码
    /// 每页记录数
    /// 查询条件
    /// 排序字段
    /// 排序方式 asc或desc
    /// 
    protected string QueryData(int pageIndex, int pageSize, string where,string orderField,string order)
    {
        int totalRecord = 0;
        int TotalPage = 0;
        string orderStr = string.IsNullOrWhiteSpace(orderField) ? "d_id asc" : string.Format("{0} {1}", orderField, order);
        DataTable dt = MSCL.PagingHelper.QueryPagingMssql("TestTable", "*", orderStr, pageIndex, pageSize, where, out totalRecord, out TotalPage);
        PageData data = new PageData();
        data.total = totalRecord;
        List list = new List();
        foreach (DataRow item in dt.Rows)
        {
            JObject obj = new JObject();
            obj.Add("d_id", item["d_id"].ToString());
            obj.Add("d_name", item["d_name"].ToString());
            obj.Add("d_password", item["d_password"].ToString());
            obj.Add("d_else", item["d_else"].ToString());
            obj.Add("d_amount", item["d_amount"].ToString());
            list.Add(obj);
        }
        data.rows = list;
        return JsonConvert.SerializeObject(data); 
    }
    #endregion

    public bool IsReusable {
        get {
            return false;
        }
    }

    public class PageData 
    {
        public int total;
        public List rows; 
    }

}

EasyUI DataGrid使用示例_第1张图片

$('#ddlFather').combotree('loadData',@Html.Raw(ViewBag.Level));
$("#ddlFather").combotree('setValue','@ViewBag.FatherId');//默认选中
var t = $('#ddlFather').combotree('tree'); // 得到树对象 
var a = t.tree('getSelected').id;  //取值
var b = t.tree('getSelected').text;  //取值


$('#ddlRole').combobox({
	data: @Html.Raw(ViewBag.RoleData),
	valueField:'GroupID',
	textField:'GroupName',
	onChange : function(){
		var value = $(this).combobox('getValue');
		$("#roleId").val(value);
		//console.log(value);
		$.ajax({
			url: '@Url.Action("GetRole", "Home")', 
			data: {"roleId": value },
			type: 'GET',
			timeout: 1000,
			cache: false,
			success: function(data){
				setCheckbox(data)
			} 
		})              
	}
});
var a = $("#ddlRole").combobox('getValue'); //取值
var a = $("#ddlRole").combobox('getText'); //取文字


$("#resourcelist").treegrid({
	title: "权限分配",
	url: '@Url.Action("GetResourceTree", "Home")',
	idField: 'moduleid',
	treeField: 'module_name',
	//rownumbers: true, //行号
	toolbar: '#tb',
	fitColumns: true,//自动适应。先给列随便加个宽度
	border: false
});

资源编号 资源名称 操作


转载于:https://www.cnblogs.com/smartsmile/p/6234050.html

你可能感兴趣的:(EasyUI DataGrid使用示例)