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

客户端:

PageData pageData=new PageData();//用来接收数据
public bool QueryByCondition(Entity.ProductStatus status, int pageIndex)
{
       SoapHeaderTransferData();//webservice 的soap身份验证,它的作用能够访问webservice服务端,如果你没有使用webservice,则不用加。
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是一页有多少条数据,也是根据需要输入
if (str == null)
{
return false;
}
else
{
          //将str反序列化,获得类实体数据
pageData = VCommons.ObjectXmlExtensions.ToObj<Entity.Ot.PageData>(VCommons.Utils.UrlDecode(str));
this.DataGridViewProduct.AutoGenerateColumns = false;//设置datagridview不能够自动添加列
this.DataGridViewProduct.DataSource = pageData.Data;
DataGridViewProduct.ClearSelection();
lblPageCount.Text = pageData.TotalPage.ToString();
lbCurrentPage.Text = pageData.PageIndex.ToString();
return true;
}
}

服务端:

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

              //进行分页操作
             var pageData = new Entity.PagedList<Entity.VAERP.Product>(pros, pageIndex, pageSize); //序列化
var str = VCommons.Utils.UrlEncode(new Entity.Ot.PageData() { Data = pageData.ToArray(), PageIndex = pageData.PageIndex, PageSize = pageData.PageSize, TotalPage = pageData.TotalPages }.ToXml());
return str;
}
}
else
{
return VCommons.Utils.UrlEncode(new Entity.PagedList<Entity.VAERP.Product>(null, pageIndex, pageSize).ToXml());
}
}
#endregion

分页方法PagedList(,,)

 public PagedList(IQueryable<T> source, int index, int pageSize)
{
if (source != null) //判断传过来的实体集是否为空
{
int total = source.Count();
this.TotalCount = total;
this.TotalPages = total / pageSize; if (total % pageSize > )
TotalPages++; this.PageSize = pageSize;
if (index > this.TotalPages)
{
index = this.TotalPages;
}
if (index < )
{
index = ;
}
this.PageIndex = index;
this.AddRange(source.Skip((index - ) * pageSize).Take(pageSize).ToList()); //Skip是跳到第几页,Take返回多少条
}
}

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. 【转】AJAX中JSON数据的返回处理问题

    AJAX处理复杂数据时,便会使用JSON格式.常用在对数据库的数据查询上.在数据库查询到数据后,便可在处理页面直接将数据转为JSON格式,然后返回. 本篇主要讨论:jQuery中,JSON数据在AJA ...

  2. ASP.NET资源大全-知识分享

    API 框架 NancyFx:轻量.用于构建 HTTP 基础服务的非正式(low-ceremony)框架,基于.Net 及 Mono 平台.官网 ASP.NET WebAPI:快捷创建 HTTP 服务 ...

  3. vs 调试 iis中的网站

    打开网站,在vs中附加进程,选择w3wp.exe,如果不能下断点,设置一下pdb文件位置

  4. curl模拟请求常用参数

    封装一个curl模拟浏览器请求的函数,如下: /** * curl模拟浏览器请求 * @param unknown $url 请求的地址 * @param array $params 请求地址所需要的 ...

  5. Zipkin分布式跟踪系统介绍

    Zipkin是什么Zipkin分布式跟踪系统:它可以帮助收集时间数据,解决在microservice架构下的延迟问题:它管理这些数据的收集和查找:Zipkin的设计是基于谷歌的Google Dappe ...

  6. 大家好,又是新的一天。今天给大家带来一些新的知识:选择器的种类和css的三种样式

    今天我们为大家 选择了 六种 选择器: 1. 标签选择器 2.id选择器 3.class选择器 4.后代选择器 5.子代选择器 6.交集选择器 我们就举三个典型的例子:后代选择器,子代选择器和交集选择 ...

  7. 工作笔记-table问题汇总(vue单文件组件)

    1.vue: computed里定义的数据,在其他地方不能再重新赋值,会报错: Computed property "xxxxxx" was assigned to but it ...

  8. 使用mybatis开发dao方法

    使用mybatis开发dao的时候, 主要涉及到SqlSessionFactoryBuilder.SqlSessionFactory.SqlSession 这三个类 现在将这三个类的使用方法简单的说下 ...

  9. Salesforce 导入导出数据简介

    导入数据的方式 有两种方式可以将数据导入Salesforce: 数据导入向导 Data Loader工具 Salesforce支持将csv文件中的数据导入系统. 数据导入向导 数据导入向导可以从设置界 ...

  10. Arcgis去除Z,M值

    在arcgis中,我们常用的数据类型有点,线,面数据,但是有时候我们在转换数据的时候经常会带有ZM值,而带ZM值的数据在有些软件中是不会显示的,也就是说显示存在问题,所以我们需要去除掉ZM值 在arc ...