这次datagridview绑定数据并分页操作,因为用到了webservice,所以代码会详细讲解。QueryByCondition是一个查询函数

客户端:

  1. PageData pageData=new PageData();//用来接收数据
    public bool QueryByCondition(Entity.ProductStatus status, int pageIndex)
  2. {
           SoapHeaderTransferData();//webservice 的soap身份验证,它的作用能够访问webservice服务端,如果你没有使用webservice,则不用加。
  3. string query_condition = txt_title.Text.Trim().ToString();//查询条件
            //返回string类型,序列化,其实是类实体转化为string,方便在webservice之间传输。
    string str = ps.QueryByCondition(query_condition, (pm.ProductStatus)Enum.Parse(typeof(pm.ProductStatus),status.ToString()),
                 user_id, pageIndex, pageSize);//有五个参数,前三个是查询条件,后两个是分页条件,pageIndex是当前页根据自己的需要输入, pageSize是一页有多少条数据,也是根据需要输入
  4. if (str == null)
  5. {
  6. return false;
  7. }
  8. else
  9. {
              //将str反序列化,获得类实体数据
  10. pageData = VCommons.ObjectXmlExtensions.ToObj<Entity.Ot.PageData>(VCommons.Utils.UrlDecode(str));
  11. this.DataGridViewProduct.AutoGenerateColumns = false;//设置datagridview不能够自动添加列
  12. this.DataGridViewProduct.DataSource = pageData.Data;
  13. DataGridViewProduct.ClearSelection();
  14. lblPageCount.Text = pageData.TotalPage.ToString();
  15. lbCurrentPage.Text = pageData.PageIndex.ToString();
  16. return true;
    }
  17. }

服务端:

  1. #region 按条件查询产品信息
  2. [SoapHeader("myHeader")]
  3. [WebMethod(EnableSession = true)]
  4. public string QueryByCondition(string query_condition, Entity.ProductStatus status, string userid, int pageIndex, int pageSize)
  5. {
          //进行身份验证
  6. if (myHeader.CheckLogin())
  7. {
  8. using (var repository = new DataE.VAERP.Repository())
  9. {
                //根据条件查询数据
  10. var linq = from product in repository.GetIQueryable<Entity.VAERP.Product>()
  11. join data in repository.GetIQueryable<Entity.VAERP.ProductData>()
  12. on product.ID equals data.ProductID
  13. where (product.UserID == userid || data.SellerID == userid) && product.Status == status
  14. select product;
  15. IQueryable<Entity.VAERP.Product> pros = string.IsNullOrWhiteSpace(query_condition) ? linq :
  16. linq.Where(item => item.Title.StartsWith(query_condition) || item.Title.EndsWith(query_condition) || item.Title.IndexOf(query_condition) != -);

  17.               //进行分页操作
                 var pageData = new Entity.PagedList<Entity.VAERP.Product>(pros, pageIndex, pageSize);
  18.  
  19. //序列化
  20. var str = VCommons.Utils.UrlEncode(new Entity.Ot.PageData() { Data = pageData.ToArray(), PageIndex = pageData.PageIndex, PageSize = pageData.PageSize, TotalPage = pageData.TotalPages }.ToXml());
  21. return str;
  22. }
  23. }
  24. else
  25. {
  26. return VCommons.Utils.UrlEncode(new Entity.PagedList<Entity.VAERP.Product>(null, pageIndex, pageSize).ToXml());
  27. }
  28. }
  29. #endregion

分页方法PagedList(,,)

  1. public PagedList(IQueryable<T> source, int index, int pageSize)
  2. {
  3. if (source != null) //判断传过来的实体集是否为空
  4. {
  5. int total = source.Count();
  6. this.TotalCount = total;
  7. this.TotalPages = total / pageSize;
  8.  
  9. if (total % pageSize > )
  10. TotalPages++;
  11.  
  12. this.PageSize = pageSize;
  13. if (index > this.TotalPages)
  14. {
  15. index = this.TotalPages;
  16. }
  17. if (index < )
  18. {
  19. index = ;
  20. }
  21. this.PageIndex = index;
  22. this.AddRange(source.Skip((index - ) * pageSize).Take(pageSize).ToList()); //Skip是跳到第几页,Take返回多少条
  23. }
  24. }

winfrom之datagridview分页显示的更多相关文章

  1. DataGridView 分页显示

    DataGridView 分页显示函数 1.获取当前页的子数据表函数 public static DataTable GetPagedTable(DataTable dt, int PageIndex ...

  2. C# DataGridView分页显示

    //导入命名空间部分省略 DBClass.DBExecute dbexecute = new DBExecute(); string connectionString = @"Data So ...

  3. winform里dataGridView分页代码,access数据库

    winform里dataGridView分页,默认dataGridView是不分页的和webform里不一样,webform中GridView自带自带了分页. 现在c/s的程序很多时候也需要webfo ...

  4. C# 实现DataGridView分页功能

    C#实现DataGridView分页功能 2010-07-17 13:45:42|  分类: C#|字号 订阅     从界面可以看到,在设计时需要一个DataGridView.BindingNavi ...

  5. C#关于分页显示

    ---<PS:本人菜鸟,大手子还请高台贵手> 以下是我今天在做分页时所遇到的一个分页显示问题,使用拼写SQL的方式写的,同类型可参考哦~ ------------------------- ...

  6. 多页的TIFF图片在aspx页面分页显示

    一.逻辑实现:将数据库中的二进制TIFF图片读出并分页显示在页面上. 1.显示界面 public FrameDimension MyGuid; ; ; public static MemoryStre ...

  7. asp.net gridview 分页显示不出来的问题

    使用gridview分页显示,在点击第二页的时候显示空白,无数据. 原因是页面刷新,绑定datatable未执行 解决方法: 1.将datatable设置为静态 2.在OnPageIndexChang ...

  8. SSRS(rdl报表)分页显示表头和对表头的冻结处理

    基础环境 最近在公司做西门子某系统的二次开发,需要用到SQLServer Reporting Services(SSRS).我们用的SQL版本是SQLServer 2008 R2:在设计报表时,表格用 ...

  9. JSP分页显示实例(基于Bootstrap)

    首先介绍一款简单利落的分页显示利器:bootstrap-paginator 效果截图: GitHub官方下载地址:https://github.com/lyonlai/bootstrap-pagina ...

随机推荐

  1. .Net Core 使用 System.Drawing.Common 部署到CentOS上遇到的问题

    一开始报这个错误:Unable to load shared library 'libdl' 找到libdl安装位置是/usr/lib64: #locate libdl /usr/lib64/libd ...

  2. TypeError: value.getTime is not a function (elementUI报错转载 )

    "TypeError: value.getTime is not a function" 2018年07月02日 16:41:24 leeleejoker 阅读数:2091 标签: ...

  3. EF Codefirst 中间表(关系表)的增删改查(转)

    EF Codefirst 多对多关系 操作中间表的 增删改查(CRUD)   前言 此文章只是为了给新手程序员,和经验不多的程序员,在学习ef和lambada表达式的过程中可能遇到的问题. 本次使用订 ...

  4. 26.QT-模型视图之自定义委托

    在上一章学习 25.QT-模型视图 后,本章接着学习视图委托 视图委托(Delegate)简介 由于模型负责组织数据,而视图负责显示数据,所以当用户想修改显示的数据时,就要通过视图中的委托来完成 视图 ...

  5. 解决mysql服务无法启动的问题

    今天,mysql突然无法启动了. 解决办法记录一下: 1.删除data文件 我的:C:\Program Files\MySQL\MySQL Server 5.7\data 注意:这个文件可能在你一直试 ...

  6. BZOJ1058: [ZJOI2007]报表统计(set)

    Time Limit: 15 Sec  Memory Limit: 162 MBSubmit: 4190  Solved: 1420[Submit][Status][Discuss] Descript ...

  7. Simplest Python K-Way Merging Sort|最简单的Python k路归并排序

    想做这个好长时间了,因为有一篇Dreamworks的论文<Coherent Out-of-Core Point-Based Global Illumination>提到了这个,一直没时间做 ...

  8. pyinstaller打包错误 UnicodeDecodeError: 'gbk' codec can't decode byte 0xab in position 160:

    注:我的博客原本在CSDN,现转到博客园,图片采用以前的图片,并没有盗图. 在将.py文件打包时,出现了下列错误 >>C:\Users\小呆\PycharmProjects\pycharm ...

  9. html之head标签

    本文内容: head标签 介绍 常用子标签 meta title link style script 首发时间:2018-02-12 修改: 2018-04-24:修改了标题名称,重新排版了内容,使得 ...

  10. Django 登录验证-自动重定向到登录页

    Web项目有些场景需要做用户登录验证,以便访问不同页面. 方法一:login_required装饰器 适用于函数视图. from django.contrib.auth.decorators impo ...