先上图吧

你得先下载一个EasyUi框架,地址:http://www.jeasyui.net/download/

在你的项目中需要引用,前台代码如下:

DDL.cshtml

<!DOCTYPE html>
<html>
<head>
    <title>DDL</title>
    <link href="../../Scripts/JqueryEasyUi/themes/default/easyui.css" rel="stylesheet"
        type="text/css" />
    <link href="../../Scripts/JqueryEasyUi/themes/icon.css" rel="stylesheet" type="text/css" />
    <script src="../../Scripts/JqueryEasyUi/jquery.min.js" type="text/javascript"></script>
    <script src="../../Scripts/JqueryEasyUi/jquery.easyui.min.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(function () {

$('#List2').datagrid({
                title: '新闻列表',
                url: 'DDL_Gd',
                method: 'get', //默认是post,不允许对静态文件访问
                width: '100%',
                iconCls: 'icon-save',
                dataType: "json",
                fitColumns: true,
                rownumbers: true, //是否加行号
                pagination: true, //是否显式分页
                pageSize: 4, //页容量,必须和pageList对应起来,否则会报错
                pageNumber: 1, //默认显示第几页
                pageList: [5,10,15, 30, 45], //分页中下拉选项的数值
                columns: [[
                    { field: 'ck', checkbox: true },
                    { field: 'Title', title: '标题' },
                    { field: 'AddUser', title: '添加人' },
                    { field: 'Content', title: '内容' },
                    { field: 'AddDate', title: '添加日期' }
                ]],
                singleSelect: false, //允许选择多行
                selectOnCheck: true, //true勾选会选择行,false勾选不选择行, 1.3以后有此选项
                checkOnSelect: true //true选择行勾选,false选择行不勾选, 1.3以后有此选项
            });
        });
    </script>
</head>
<body>
    <div>
        <div style="margin: 10px 0;">
        </div>
        <table id="List2" class="easyui-datagrid">
        </table>
    </div>
</body>
</html>

控制层代码:

NewsControl.cs

NewsDbContent db = new NewsDbContent();

public ActionResult DDL()
        {
            return View();
        }

public ActionResult DDL_Gd()
        {
            int pageSize = 5;
            int pageIndex = 1;
            int.TryParse(this.Request["page"], out pageIndex);
            int.TryParse(this.Request["rows"], out pageSize);
            pageSize = pageSize <= 0 ? 5 : pageSize;
            pageIndex = pageIndex < 1 ? 1 : pageIndex;

var json = db.Newss.OrderBy(n => n.Id).Skip<News>((pageIndex - 1) * pageSize).Take<News>(pageSize).ToList<News>();
            return Json(json, JsonRequestBehavior.AllowGet);
        }

Models文件下的代码文件(两个代码文件News.cs、NewsDbContent.cs)

News.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;

namespace NewsMvc.Models
{
    public class News
    {
        [Display(Name="编号")]
        public int Id { get; set; }
        [Required(ErrorMessage = "标题必填")]
        [Display(Name="标题")]
        public string Title { get; set; }
        [Display(Name="添加人")]
        public string AddUser { get; set; }
        [Display(Name="内容")]
        public string Content { get; set; }
        [Display(Name="添加时间")]
        [DisplayFormat(DataFormatString="{0:yyyy-MM-dd}")]
        public DateTime AddDate { get; set; }
    }
}

NewsDbContent.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Entity;
using System.Data.Objects.DataClasses;

namespace NewsMvc.Models
{
    public class NewsDbContent : DbContext
    {
        public DbSet<News> Newss { get; set; }
    }
}

web.config配置文件:

<?xml version="1.0" encoding="utf-8"?>
<!--
  有关如何配置 ASP.NET 应用程序的详细信息,请访问
  http://go.microsoft.com/fwlink/?LinkId=152368
  -->
<configuration>
  <appSettings>
    <add key="webpages:Version" value="1.0.0.0" />
    <add key="ClientValidationEnabled" value="true" />
    <add key="UnobtrusiveJavaScriptEnabled" value="true" />
  </appSettings>
  <connectionStrings>
    <add name="NewsDbContent" connectionString="Data Source=.;Initial Catalog=News;Integrated Security=true;" providerName="System.Data.SqlClient" />
  </connectionStrings>
  <system.web>
    <compilation debug="true" targetFramework="4.0">
      <assemblies>
        <add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Web.Helpers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Web.WebPages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
      </assemblies>
    </compilation>
    <authentication mode="Forms">
      <forms loginUrl="~/Account/LogOn" timeout="2880" />
    </authentication>
    <pages>
      <namespaces>
        <add namespace="System.Web.Helpers" />
        <add namespace="System.Web.Mvc" />
        <add namespace="System.Web.Mvc.Ajax" />
        <add namespace="System.Web.Mvc.Html" />
        <add namespace="System.Web.Routing" />
        <add namespace="System.Web.WebPages" />
      </namespaces>
    </pages>
  </system.web>
  <system.webServer>
    <validation validateIntegratedModeConfiguration="false" />
    <modules runAllManagedModulesForAllRequests="true" />
  </system.webServer>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

Sql数据库代码,数据库叫News

USE [News]
GO
/****** 对象:  Table [dbo].[News]    脚本日期: 08/13/2015 11:09:16 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[News](
    [Id] [int] IDENTITY(1,1) NOT NULL,
    [Title] [nvarchar](max) COLLATE Chinese_PRC_CI_AS NULL,
    [AddUser] [nvarchar](max) COLLATE Chinese_PRC_CI_AS NULL,
    [Content] [nvarchar](max) COLLATE Chinese_PRC_CI_AS NULL,
    [AddDate] [datetime] NULL,
 CONSTRAINT [PK__News__7E6CC920] PRIMARY KEY CLUSTERED
(
    [Id] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]

.Net的DataGrid的使用的更多相关文章

  1. ASP.NET Aries 入门开发教程7:DataGrid的行操作(主键操作区)

    前言: 抓紧勤奋,再接再励,预计共10篇来结束这个系列. 上一篇介绍:ASP.NET Aries 入门开发教程6:列表数据表格的格式化处理及行内编辑 本篇介绍主键操作区相关内容. 1:什么时候有默认的 ...

  2. JQuery easyUI DataGrid 创建复杂列表头(译)

    » Create column groups in DataGrid The easyui DataGrid has ability to group columns, as the followin ...

  3. ASP.NET Aries DataGrid 配置表头说明文档

    DataGrid 配置表头 字段 中文 说明 Field 字段 注意:mg_ 开头的字段为层级表头 Title 列称 OrderNum 序号 显示的顺序(冻结和非冻结列是两个组的序号) Width 列 ...

  4. ASP.NET Aries JSAPI 文档说明:AR.DataGrid、AR.Dictionary

    AR.Global 文档 1:对象或属性: 名称 类型 说明 DG 对象 DataGrid操作对象 //datagrid集合,根据ID取出DataGrid对象,将Json当数组用. Items: ne ...

  5. ASP.NET Aries JSAPI 文档说明:AR.DataGrid

    AR.DataGrid 文档 用法: <body> <table id="dg"></table> </body> </htm ...

  6. ASP.NET MVC5+EF6+EasyUI 后台管理系统(7)-MVC与EasyUI DataGrid

    系列目录 本节知识点 为了符合后面更新后的重构系统,文章于2016-11-1日重写 EasyUI读取MVC后台Json数据 开始实现 我们的系统似乎越来越有趣了 首先从前端入手,开打View下面的Sh ...

  7. 构建ASP.NET MVC4+EF5+EasyUI+Unity2.x注入的后台管理系统(8)-MVC与EasyUI DataGrid 分页

    系列目录 前言 为了符合后面更新后的重构系统,文章于2016-11-1日重写 EasyUI Datagrid在加载的时候会提交一些分页的信息到后台,我们需要根据这些信息来进行数据分页再次返回到前台 实 ...

  8. 控制EasyUI DataGrid高度

    这次要说的是控制EasyUI的高度,平时我公司的项目,用EasyUI较多,然后datagrid这个组件是用的非常多的.平时我们都是固定高度,常见代码如下:             <table  ...

  9. GridView/DataGrid行单击和双击事件实现代码_.Net教程

    功能: 单击选中行,双击打开详细页面 说明:单击事件(onclick)使用了 setTimeout 延迟,根据实际需要修改延迟时间 ;当双击时,通过全局变量 dbl_click 来取消单击事件的响应  ...

  10. WPF DataGrid 行选中相关

    DataGrid选中行是有自带SelectionChanged的,可是当需要重复选中同一行时,该事件就不会触发了. 后来反复查资料找到了DataGrid上有个DataGridRow. DataGrid ...

随机推荐

  1. 【R】如何确定最适合数据集的机器学习算法 - 雪晴数据网

          [R]如何确定最适合数据集的机器学习算法 [R]如何确定最适合数据集的机器学习算法 抽查(Spot checking)机器学习算法是指如何找出最适合于给定数据集的算法模型.本文中我将介绍八 ...

  2. 遇到了IAR烧写程序出错,附解决办法The stack plug-in failed to set a breakpoint on "main"

    今天做无线串口调试的时候用IAR7.51往CC2530无线模块烧程序的时候遇到了问题: 先是下载过程中有许多警告,然后就是提示无法跳断点,找不到main方法,每次烧程序都出现: The stack p ...

  3. 清除浮动(clearfix hack)

    eg:

  4. 【bzoj3631】[JLOI2014]松鼠的新家

    题目描述 松鼠的新家是一棵树,前几天刚刚装修了新家,新家有n个房间,并且有n-1根树枝连接,每个房间都可以相互到达,且俩个房间之间的路线都是唯一的.天哪,他居然真的住在"树"上.松 ...

  5. 【bzoj2060】[Usaco2010 Nov]Visiting Cows拜访奶牛

    题目描述 经过了几周的辛苦工作,贝茜终于迎来了一个假期.作为奶牛群中最会社交的牛,她希望去拜访N(1<=N<=50000)个朋友.这些朋友被标号为1..N.这些奶牛有一个不同寻常的交通系统 ...

  6. 【C语言入门教程】4.4 指针 与 指针变量

    在程序中声明变量后,编译器就会为该变量分配相应的内存单元.也就是说,每个变量在内存会有固定的位置,有具体的地址.由于变量的数据类型不同,它所占的内存单元数也不相同.如下列声明了一些变量和数组. int ...

  7. 网络编程3-URL编程(URL)

    1.URL(Uniform Resource Locatior) 统一资源占位符,表示Intenet上某一资源的地址 2.URL的组成部分 传输协议:主机名:端口号:文件名 例:http://192. ...

  8. servlet过滤器实现维护项目

    最近公司需要系统维护,提出要建一个维护系统,要求: 1.访问公司域名跳到系统首页 2.点击首页的任意按钮给出维护提示信息 3.用户访问之前收藏的任意系统链接跳转到首页 下面介绍下用过滤器实现上述需求 ...

  9. fontconfig编译出错

    编译fontconfig编译时出错: 出错configure: error: You must have freetype installed; see http://www.freetype.org ...

  10. iOS开发——常见错误——使用MJRefresh返回上一个界面蹦掉的情况

    最近在使用MJRefresh框架时发现了一个bug 下面是我的源代码 前一个界面 -(void)tableView:(UITableView *)tableView didSelectRowAtInd ...