将数据库中大量数据以JSON格式传给JQGrid MVC4+JQGrid
来源:互联网 发布:医学继续教育网络 编辑:程序博客网 时间:2024/05/16 01:42
目的:将数据库中大量数据传递给JQGrid显示在界面
技术:MVC4+JQGrid
步骤:1、创建model,读取数据库中的数据到DataSet,遍历每一行的数据并赋值给model中的实体对象,添加到List
2、将list数据转换为JSON数据,使用Jquer传递给JQGrid
实现过程:
将数据添加到list:
List<demoObject> demo = new List<demoObject>(); public string getAllInfo() { DataSet ds = DBhelper.getJsonInfo(); DataTable dt = ds.Tables["Base_Module"]; foreach (DataRow row in dt.Rows) { demo.Add(new demoObject(){ModuleId=row["ModuleId"].ToString(),ParentId=row["ParentId"].ToString(),Categroy=row["Category"].ToString(),Code=row["Code"].ToString(),FullName=row["FullName"].ToString(),Icon=row["Icon"].ToString(),Location=row["Location"].ToString(),Target=row["Target"].ToString(),Level=(int)row["Level"],Isexpand=(int)row["Isexpand"],AllowButton=(int)row["AllowButton"],AllowView=(int)row["AllowView"],AllowForm=(int)row["AllowForm"],Authority=(int)row["Authority"],DataScope=(int)row["DataScope"],Remark=row["Remark"].ToString(),Enabled=(int)row["Enabled"],SortCode=(int)row["SortCode"],DeleteMark=(int)row["DeleteMark"],CreateDate=row["CreateDate"].ToString(),CreateUserId=row["CreateUserId"].ToString(),CreateUserName=row["CreateUserName"].ToString(),ModifyDate=row["ModifyDate"].ToString(),ModifyUserId=row["ModifyUserId"].ToString(),ModifyUserName=row["ModifyUserName"].ToString()}); } string json = ToJsJson(demo); return json; }
//将list转化为json数据的主要方法编辑以下方法之前需要添加引用
//System.Runtime.Serialization;先添加右键引用
//System.IO
public static string ToJsJson(object item) { DataContractJsonSerializer serializer = new DataContractJsonSerializer(item.GetType()); using (MemoryStream ms = new MemoryStream()) { serializer.WriteObject(ms, item); StringBuilder sb = new StringBuilder(); sb.Append(Encoding.UTF8.GetString(ms.ToArray())); return sb.ToString(); } }
1 0
- 将数据库中大量数据以JSON格式传给JQGrid MVC4+JQGrid
- JQGRID读取json数据的格式要求
- 通过Json格式将数据传给服务端
- jqGrid绑定Json数据
- jqgrid 取全部的数据转成json格式
- jqgrid--动态传递json数据
- JQGrid通过json请求nodejs数据,表格信息保存在mysql数据库中
- jqgrid json
- jqgrid后台输出json的格式
- jqgrid:网格显示数据库中取出的数据
- 将SQL Server的任意记录转换为JSON格式(JQGRID) -- 支持SQL 2005
- jqGrid初始化加载本地json数据
- JQGrid二种方法加载Json数据
- jQuery表格插件jqGrid之JSON数据
- jqGrid
- Jqgrid
- JQGrid
- JQGrid
- iOS开发拓展篇—应用之间的跳转和数据传
- 机器学习3
- 树莓派连接触摸屏方法(Raspberry Pi 3.5寸 B/B+/2B LCD液晶屏)
- 安卓下的多线程
- UVa11054--Wine trading in Gergovia(贪心)
- 将数据库中大量数据以JSON格式传给JQGrid MVC4+JQGrid
- hdu1011 Starship Troopers
- Android下自动折行 效果
- CF 554B Ohana Cleans Up
- iOS开发拓展篇- 即时通讯XMPP简单介绍
- 【NGUI】Unity中ScrollView3D滚动效果
- hadoop伪分布式搭建
- 接口回调
- iOS开发实用技巧篇—项目新特性页面的处理