星空网 > 软件开发 > ASP.net

winfrom之datagridview分页显示

这次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.Object(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) != -1);
              //进行分页操作
             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 }.Toreturn str; } } else { return VCommons.Utils.UrlEncode(new Entity.PagedList<Entity.VAERP.Product>(null, pageIndex, pageSize).To#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 > 0)          TotalPages++;        this.PageSize = pageSize;        if (index > this.TotalPages)        {          index = this.TotalPages;        }        if (index < 1)        {          index = 1;        }        this.PageIndex = index;        this.AddRange(source.Skip((index - 1) * pageSize).Take(pageSize).ToList()); //Skip是跳到第几页,Take返回多少条      }    }

 




原标题:winfrom之datagridview分页显示

关键词:GridView

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

lazada泰国市场周报:疫情下这些产品的商机来了:https://www.ikjzd.com/articles/119775
【小白福音】跨境电子商务基本概念:https://www.ikjzd.com/articles/119776
疫情冲击之下,运动鞋转售市场该如何自救?:https://www.ikjzd.com/articles/119777
海外独立站设计中常被忽视的部分:https://www.ikjzd.com/articles/119778
【跨境卖家必收藏】了解跨境融资租赁的实践:https://www.ikjzd.com/articles/119779
跨境电商独立站布局了这个渠道,ROI提高到600%:https://www.ikjzd.com/articles/119780
长治婚庆女司仪和主持人:https://www.vstour.cn/a/366176.html
北京丰台区水上乐园哪家好玩?:https://www.vstour.cn/a/366177.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流