EasyUI笔记(六)数据表格
用asp.net结合easyui做个一个数据网格的页面,包括对数据的增删改查,界面如下:

<body><table id="tb1"></table><div id="tb" style="padding:5px"><div style="margin-bottom:5px"><a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-reload'" onclick="reload()">刷新</a><a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-add'" onclick="Add()">添加</a><a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-edit'" onclick="edit()">修改</a><a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-remove'" onclick="destroy()">删除</a></div><div>查询名称:<input type="text" id="Eq" name="Eq" style="width:150px"/><select id="order" class="easyui-combobox" style="width:100px"><option value="asc">升序</option><option value="desc">降序</option></select><a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-search'" onclick="obj.search()">查询</a></div></div><%-- 弹窗 Start--%><div id="dlg" class="easyui-dialog" style="width:400px;height:320px;padding:10px 20px" data-options="closed:true,buttons:'#dlg-buttons'"><div class="ftitle">设备信息</div><form id="fm" method="post" novalidate="novalidate"><div class="fitem"><label>产品编号:</label><input id="ProductID" name="ProductID" class="easyui-validatebox" data-options="required:false"/></div><div class="fitem"><label>产品名称:</label><input id="Name" name="Name" class="easyui-validatebox" data-options="required:true"/></div><div class="fitem"><label>描述:</label><input id="Description" name="Description" class="easyui-validatebox" data-options="required:true"/></div><div class="fitem"><label>种类:</label><input id="Category" name="Category" class="easyui-validatebox" data-options="required:true"/></div><div class="fitem"><label>价格:</label><input id="Price" name="Price" class="easyui-validatebox" data-options="required:true,validType:'intOrFloat'"/></div></form></div><div id="dlg-buttons"><a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-ok'" onclick="save()" style="width:90px">Save</a><a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-cancel'" onclick="javascript:$('#dlg').dialog('close')" style="width:90px">Cancel</a></div><%-- 弹窗 End --%></body>
$(function () {$('#tb1').datagrid({url: '../Handler/GetDataFormSql.ashx',width: 1200,title: '管理',method: 'get',toolbar: '#tb',//rownumbers: true,singleSelect:true,columns: [[{ field: 'ProductID', title: '编号', width: 150 },{ field: 'Name', title: '名称', width: 150 },{ field: 'Description', title: '描述', width: 250 },{ field: 'Category', title: '种类', width: 150 },{ field: 'Price', title: '价格', width: 150 }]],pagination: true,pageSize: 20,pageList: [20, 30 , 40]});})
public void ProcessRequest(HttpContext context){context.Response.ContentType = "text/plain";int page = 1, rows = 10;//EasyUI自带的两个参数rows与page ,表示当前页与行数if (context.Request.QueryString["rows"] != null){rows = int.Parse(context.Request.QueryString["rows"].ToString().Trim());}if (context.Request.QueryString["page"] != null){page = int.Parse(context.Request.QueryString["page"].ToString().Trim());}//查询分页 stratIndex endIndexint stratIndex, endIndex;stratIndex = (page - 1) * rows + 1;endIndex = page * rows;//查询排序 key orderstring key = "", order = "desc";if (context.Request.QueryString["key"] != null){key = context.Request.QueryString["key"].ToString().Trim();}if (context.Request.QueryString["order"] != null){order = context.Request.QueryString["order"].ToString().Trim();}//设置模糊查询StringBuilder sqlWhere = new StringBuilder();if (key != "") {sqlWhere.AppendFormat("upper(ProductID) like '%{0}%' or "+"upper(Name) like '%{0}%' or "+"upper(Description) like '%{0}%' or " +"upper(Category) like '%{0}%' or " +"upper(Price) like '%{0}%'",key);}//查询数据库DAL.SqlHelper sqlhelper = new DAL.SqlHelper();//获取查询数据的行数int count = sqlhelper.EUGetRecordCount(sqlWhere.ToString());//封装数据到datasetDataSet ds = sqlhelper.GetListByPagebykey(sqlWhere.ToString(), order, stratIndex, endIndex);//将dataset转化为Json格式string strToJon = DAL.ToJson.DatasetJson(ds, count);context.Response.Write(strToJon);context.Response.End();}
public int EUGetRecordCount(string key){StringBuilder strSql = new StringBuilder();strSql.Append("select count(1) FROM Products ");if (key.Trim() != ""){strSql.Append("where " + key);}object obj = DBHelper.GetSingle(strSql.ToString());if (obj == null){return 0;}else{return Convert.ToInt32(obj);}}public DataSet GetListByPagebykey(string Key, string order, int startIndex, int endIndex){StringBuilder strSql = new StringBuilder();strSql.Append("SELECT * FROM ( ");strSql.Append(" SELECT ROW_NUMBER() OVER (");if (!string.IsNullOrEmpty(Key.Trim())){strSql.Append("order by T." + Key+" " + order);}else{strSql.Append("order by T.ProductID asc");}strSql.Append(")AS Row, T.* from Products T ");if (!string.IsNullOrEmpty(Key.Trim())){strSql.Append(" WHERE " + Key);}strSql.Append(" ) TT");strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);return DBHelper.Query(strSql.ToString());}
public class ToJson{/// <summary>/// DataSet转换成Json格式/// </summary>/// <param name="ds">DataSet</param>/// <returns></returns>public static string DatasetJson(DataSet ds, int total = -1){StringBuilder json = new StringBuilder();foreach (DataTable dt in ds.Tables){json.Append("{\"total\":");if (total == -1){json.Append(dt.Rows.Count);}else{json.Append(total);}json.Append(",\"rows\":");json.Append(DataTableJson(dt));json.Append("]}");} return json.ToString();}private static string DataTableJson(DataTable dt){StringBuilder jsonBuilder = new StringBuilder();jsonBuilder.Append("[");for (int i = 0; i < dt.Rows.Count; i++){jsonBuilder.Append("{");for (int j = 0; j < dt.Columns.Count; j++){jsonBuilder.Append("\"");jsonBuilder.Append(dt.Columns[j].ColumnName);jsonBuilder.Append("\":\"");jsonBuilder.Append(dt.Rows[i][j].ToString());jsonBuilder.Append("\",");}jsonBuilder.Remove(jsonBuilder.Length - 1, 1);jsonBuilder.Append("},");}jsonBuilder.Remove(jsonBuilder.Length - 1, 1);return jsonBuilder.ToString();}}
public int Add(Products model){StringBuilder strSql = new StringBuilder();strSql.Append("insert into Products(");strSql.Append("Name,Description,Category,Price)");strSql.Append(" values (");strSql.Append("@Name,@Description,@Category,@Price)");strSql.Append(";select @@IDENTITY");SqlParameter[] parameters = {new SqlParameter("@Name", SqlDbType.NVarChar,255),new SqlParameter("@Description", SqlDbType.NVarChar,255),new SqlParameter("@Category", SqlDbType.NVarChar,255),new SqlParameter("@Price ", SqlDbType.Decimal,255),};//parameters[0].Value = model.ProductID;parameters[0].Value = model.Name;parameters[1].Value = model.Description;parameters[2].Value = model.Category;parameters[3].Value = model.Price;object obj = DBHelper.GetSingle(strSql.ToString(), parameters);if (obj == null){return 0;}else{return Convert.ToInt32(obj);}}
EasyUI笔记(六)数据表格的更多相关文章
- 第二百二十二节,jQuery EasyUI,DataGrid(数据表格)组件
jQuery EasyUI,DataGrid(数据表格)组件 学习要点: 1.加载方式 2.分页功能 本节课重点了解 EasyUI 中 DataGrid(数据表格)组件的使用方法,这个组件依赖于 Pa ...
- 第二百二十四节,jQuery EasyUI,ComboGrid(数据表格下拉框)组件
jQuery EasyUI,ComboGrid(数据表格下拉框)组件 学习要点: 1.加载方式 2.属性列表 3.方法列表 本节课重点了解 EasyUI 中 ComboGrid(数据表格下拉框)组件的 ...
- jQuery EasyUI/TopJUI实现数据表格的增删改查功能(不写js,纯HTML实现!!!)
jQuery EasyUI/TopJUI实现数据表格的增删改查功能(不写js,纯HTML实现!!!) 废话不多说,直接贴上代码 <table id="configEdatagrid&q ...
- Jquery EasyUI datagrid后台数据表格生成及分页详解
由于项目原因,网站后台需要对用户信息进行各种操作,有时还需要进行批量操作,所以首先需要将用户信息展示出来,查了不少资料.发现Jquery EasyUI确实是一个不错的选择,功能强大,文档也比较全面,而 ...
- (五)EasyUI使用——datagrid数据表格
DataGrid以表格形式展示数据,并提供了丰富的选择.排序.分组和编辑数据的功能支持.DataGrid的设计用于缩短开发时间,并且使开发人员不需要具备特定的知识.它是轻量级的且功能丰富.单元格合并. ...
- DataGrid( 数据表格) 组件[9]
本节课重点了解 EasyUI 中 DataGrid(数据表格)组件的使用方法,这个组件依赖于Panel(面板).Resizeable(调整大小).LinkButton(按钮).Pageination( ...
- DataGrid( 数据表格) 组件[8]
本节课重点了解 EasyUI 中 DataGrid(数据表格)组件的使用方法,这个组件依赖于Panel(面板).Resizeable(调整大小).LinkButton(按钮).Pageination( ...
- DataGrid( 数据表格) 组件[7]
本节课重点了解 EasyUI 中 DataGrid(数据表格)组件的使用方法,这个组件依赖于Panel(面板).Resizeable(调整大小).LinkButton(按钮).Pageination( ...
- DataGrid( 数据表格) 组件[6]
本节课重点了解 EasyUI 中 DataGrid(数据表格)组件的使用方法,这个组件依赖于Panel(面板).Resizeable(调整大小).LinkButton(按钮).Pageination( ...
- DataGrid( 数据表格) 组件[5]
本节课重点了解 EasyUI 中 DataGrid(数据表格)组件的使用方法,这个组件依赖于Panel(面板).Resizeable(调整大小).LinkButton(按钮).Pageination( ...
随机推荐
- 小程序redio 样式
小程序 radio 不写样式大概是这样的 数据为测试数据. 为了增加用户体验我们一下 美化后大概是这样的 给他设定头部.左边间距 ,和自身最小宽度 上代码: wxml: <radio-group ...
- [python之路]简单介绍
python介绍 #python是一个什么样的语言?编译型和解释型静态语言和动态语言强类型定义语言和弱类型定义语言python是一门动态解释性的强类型定义语言. #Python的优缺点##优点Pyth ...
- python练习——第1题
原GitHub地址:https://github.com/Yixiaohan/show-me-the-code 题目:做为 Apple Store App 独立开发者,你要搞限时促销,为你的应用生成激 ...
- 安装symfony3.4的坑,也是PHP7.3的经典坑之解决办法
对于刚入手symfony3.4的同学,肯定会发现,安装symfony后部署后看到的往往不是hello world,也不是symfony的欢迎页面,而是给你一个下马威,唉,给你来个bug开开胃. 当然这 ...
- 在CentOS8 上安装Python3
从centos开始入手学习linux.感觉安装python很费劲,之前centos6因为python2和python3兼容的问题一直无法彻底解决,python3一旦安装影响到python2,cento ...
- PBFT算法java实现
PBFT 算法的java实现(上) 在这篇博客中,我会通过Java 去实现PBFT中结点的加入,以及认证.其中使用socket实现网络信息传输. 关于PBFT算法的一些介绍,大家可以去看一看网上的博客 ...
- NR / 5G - The Round Robin algorithm
- 注销Apache
到D:\phpTools\Apache24\bin下运行cmd 输入httpd.exe -k uninstall -n apache24 回车后提示注销完成 接着把Apache的文件删了即可
- Idea生成代码段
使用快捷键(ctrl+alt+s)找到:从idea的菜单File->Settings->Editor->Live Templates 先添加Template Group,然后添加Li ...
- React之拆分组件与组件之间的传值
父子组件传值: 父组件向子组件传值通过向子组件TodoItem进行属性绑定(content={item}.index={index}),代码如下 getTodoItem () { return thi ...