EasyUI 之 DataGrid的两种赋值方法
方法一:使用ViewData赋值
首先,我们创建一个User的实体类
- public class User
- {
- public string UserID;
- public string UserName;
- public string Sex;
- }
然后,我们在Action中添加假数据,并将假数据放到ViewData中
- public ActionResult test()
- {
- List<User> listUser = new List<User>();
- listUser.Add(new User
- {
- UserID = "001",
- UserName = "呵呵",
- Sex = "男"
- });
- listUser.Add(new User
- {
- UserID = "002",
- UserName = "哈哈",
- Sex = "女"
- }); listUser.Add(new User
- {
- UserID = "003",
- UserName = "嘿嘿",
- Sex = "男"
- });
- ViewData["listUser"] = listUser;
- return View();
- }
最后,我们在前台用ViewData给DataGrid赋值
- <div>
- <table id="dg" class="easyui-datagrid" style="width: 600px; height: 300px" >
- <thead>
- <tr>
- <th data-options="field:'UserID',width:148,sortable:true">ID</th>
- <th data-options="field:'UserName',width:148,sortable:true">姓名</th>
- <th data-options="field:'Sex',width:148,sortable:true">性别</th>
- </tr>
- </thead>
- @foreach (ITOO.EvaluationUI.Models.User enUser in ViewData["listUser"] as List<ITOO.EvaluationUI.Models.User>)
- {
- <tr>
- <td>@enUser.UserID </td>
- <td>@enUser.UserName </td>
- <td>@enUser.Sex </td>
- </tr>
- }
- </table>
- </div>
方法二:使用url赋值
首先,我们在前台的DataGrid中加上URL属性
- <div>
- <table id="dg" class="easyui-datagrid" style="width: 600px; height: 300px" >
- <thead>
- <tr>
- <th data-options="field:'UserID',width:148,sortable:true">ID</th>
- <th data-options="field:'UserName',width:148,sortable:true">姓名</th>
- <th data-options="field:'Sex',width:148,sortable:true">性别</th>
- </tr>
- </thead>
- </table>
- </div>
- <!--datagrid基本设置-->
- <script type="text/javascript">
- $(function () {
- $('#dg').datagrid({
- title: '测试表格',
- url: "/EvaluationSituation/jsonTest",
- pagination: true,//显示分页工具栏
- });
- });
- </script>
然后,我们在相应的控制器中添加一个得到json数据的方法
- public JsonResult jsonTest()
- {
- List<User> listUser = new List<User>();
- listUser.Add(new User {
- UserID ="001",
- UserName="呵呵",
- Sex ="男"
- });
- listUser.Add(new User
- {
- UserID = "002",
- UserName = "哈哈",
- Sex = "女"
- }); listUser.Add(new User
- {
- UserID = "003",
- UserName = "嘿嘿",
- Sex = "男"
- });
- JsonResult jsonUser = new JsonResult();
- jsonUser = Json(listUser);
- return jsonUser;
- }
上面介绍的两种方法能够解决我们给DataGrid赋值的问题,其中方法二里面除了将List集合转换成Json对象以外,我们还可以自己写一个方法将List转换成Json格式的字符串,这样也可以给DataGrid赋值。虽然我们能够赋值,但是这样做也有一些其他的问题,比如说怎么它的分页怎么实现,这就是下一节将要讲解的内容
EasyUI 之 DataGrid的两种赋值方法的更多相关文章
- Java中String对象两种赋值方式的区别
本文修改于:https://www.zhihu.com/question/29884421/answer/113785601 前言:在java中,String有两种赋值方式,第一种是通过“字面量”赋值 ...
- 关于String的两种赋值方式
String的两种赋值是不同的,String str1=“hello”,指向堆内存中的"hello",而String str2=new String("hello&quo ...
- 史上最全的CSS hack方式一览 jQuery 图片轮播的代码分离 JQuery中的动画 C#中Trim()、TrimStart()、TrimEnd()的用法 marquee 标签的使用详情 js鼠标事件 js添加遮罩层 页面上通过地址栏传值时出现乱码的两种解决方法 ref和out的区别在c#中 总结
史上最全的CSS hack方式一览 2013年09月28日 15:57:08 阅读数:175473 做前端多年,虽然不是经常需要hack,但是我们经常会遇到各浏览器表现不一致的情况.基于此,某些情况我 ...
- bind()函数的深入理解及两种兼容方法分析
在JavaScript中,bind()函数仅在IE9+.Firefox4+.Chrome.Safari5.1+可得到原生支持.本文将深入探讨bind()函数并对两种兼容方法进行分析比较.由于本文将反复 ...
- 菜鸡的Java笔记 第十三 String 类的两种实例化方法
String 类的两种实例化方法 String 类的两种实例化方式的区别 String 类对象的比较 Stirng 类对象的使用分析 /* 1.String 类的两种实例化方式的区别 ...
- angular2系列教程(十)两种启动方法、两个路由服务、引用类型和单例模式的妙用
今天我们要讲的是ng2的路由系统. 例子
- git两种合并方法 比较merge和rebase
18:01 2015/11/18git两种合并方法 比较merge和rebase其实很简单,就是合并后每个commit提交的id记录的顺序而已注意:重要的是如果公司用了grrit,grrit不允许用m ...
- easyui里弹窗的两种表现形式
easyui里弹窗的两种表现形式 博客分类: jQueryEasyUi 1.主JSP页面中描绘弹窗 <div id="centerDiv" data-options= ...
- 两种Ajax方法
两种Ajax方法 Ajax是一种用于快速创建动态网页的技术,他通过在后台与服务器进行少量的数据交换,可以实现网页的异步更新,不需要像传统网页那样重新加载页面也可以做到对网页的某部分作出更新,现在这项技 ...
随机推荐
- _00017 Kafka的体系结构介绍以及Kafka入门案例(0基础案例+Java API的使用)
博文作者:妳那伊抹微笑 itdog8 地址链接 : http://www.itdog8.com(个人链接) 博客地址:http://blog.csdn.net/u012185296 博文标题:_000 ...
- Android开发之视图动画基础
Android的animation由四种类型组成 XML中 alpha 渐变透明度动画效果 scale 渐变尺寸伸缩动画效果 translate 画面转换位置移动动画效果 rotate 画面转移旋转 ...
- CoreData 从入门到精通 (一) 数据模型 + CoreData 栈的创建
CoreData 是 Cocoa 平台上用来管理模型层数据和数据持久化的一个框架,说简单点,就是一个数据库存储框架.CoreData 里相关的概念比较多,而且初始化也非常繁琐,所以对初学者的学习还是有 ...
- composer是什么
composer是什么 Composer 是 PHP5.3以上 的一个依赖管理工具.它允许你声明项目所依赖的代码库,它会在你的项目中为你安装他们.Composer 不是一个包管理器.是的,它涉及 &q ...
- BZOJ 2844 高斯消元 线性基
思路: //By SiriusRen #include <cstdio> #include <cstring> #include <algorithm> using ...
- sql中计算百分比
sql中计算百分比:(转成字符串然后拼接%) ),) AS CHAR),'%') as aa from act_canal; 效果:
- 启动项目报错:org.springframework.beans.factory.UnsatisfiedDependencyException
dubbo项目: 启动项目报错:(web端) org.springframework.beans.factory.UnsatisfiedDependencyException: Error creat ...
- Android开发中,9-patch (九宫格)图片作为背景带来的问题
9-patch 为了解决不同分屏下的图片适应性,对图片做了padding,而在android中,要给一个控件设置背景图,最终是要调用 setBackgroundDrawable 方法来设置图片资源, ...
- Python内置数据结构之列表list
1. Python的数据类型简介 数据结构是以某种方式(如通过编号)组合起来的数据元素(如数.字符乃至其他数据结构)集合.在Python中,最基本的数据结构为序列(sequence). Python内 ...
- iptables 简单介绍及应用 Linux防火墙
iptables 即 Linux防火墙 的简单介绍及使用 iptables生效位置如下图: 其中, 网络防火墙也可以使用一台启用了iptables的Linux主机代替; 路由器或集线器等设施在拓扑中省 ...