当前位置:网站首页>创建自定义分页控件
创建自定义分页控件
2022-07-28 16:20:00 【mojocube】
在做JAVA项目的时候,写了一个分页控件,想着C#的朋友有可能需要,就用C#写了一个,数据方面分页的方法网上很多,就不重复了,话不多说,下面是UI端代码:
/// <summary>
/// 创建自定义分页控件,返回HTML代码
/// </summary>
/// <returns></returns>
private string CreatePager()
{
StringBuilder sb = new StringBuilder();
//当前页
int currPage = 1;
//获取URL页码参数
if (Request.QueryString["page"] != null)
{
currPage = int.Parse(Request.QueryString["page"]);
}
//总页数
int pageCount = 18;
//显示页码数
int pageNum = 5;
/以上参数是可以动态调整的,下面是算法/
//上一页
int prevPage = 1;
//下一页
int nextPage = prevPage + pageNum;
sb.Append("<ul class=\"pagination\">");
//首页
sb.Append("<li class=\"paginate_button previous\"><a href=\"Name.aspx?active=11,12&page=1\">首页</a></li>");
int count = 0;
int currCount = 0;
for (int i = 1; i <= pageCount; i++)
{
if (i == currPage)
{
currCount = count;
}
if (i % pageNum == 0)
{
if (i < pageCount)
{
count++;
}
}
}
if (currPage > pageNum)
{
prevPage = pageNum * currCount;
sb.Append("<li class=\"paginate_button\"><a href=\"Name.aspx?active=11,12&page=" + prevPage.ToString() + "\">...</a></li>");
}
int start = pageNum * currCount + 1;
int end = pageNum * currCount + pageNum;
for (int i = start; i <= end; i++)
{
if (i <= pageCount)
{
if (i == currPage)
{
sb.Append("<li class=\"paginate_button active\"><a href=\"Name.aspx?active=11,12&page=" + i.ToString() + "\">" + i.ToString() + "</a></li>");
}
else
{
sb.Append("<li class=\"paginate_button\"><a href=\"Name.aspx?active=11,12&page=" + i.ToString() + "\">" + i.ToString() + "</a></li>");
}
}
}
if (currCount < count)
{
nextPage = pageNum * currCount + nextPage;
sb.Append("<li class=\"paginate_button\"><a href=\"Name.aspx?active=11,12&page=" + nextPage.ToString() + "\">...</a></li>");
}
//尾页
sb.Append("<li class=\"paginate_button next\"><a href=\"Name.aspx?active=11,12&page=" + pageCount.ToString() + "\">尾页</a></li>");
sb.Append("</ul>");
return sb.ToString();
}边栏推荐
- 批量下载文件
- Unity shader global fog effect
- SUSE CEPH rapid deployment – storage6
- 海康威视回应'美国禁令'影响:目前所使用的元器件都有备选
- Fine-grained Fact Verification with Kernel GA Network
- 综合设计一个OPPE主页--页面的售后服务
- Alibaba cloud MSE supports go language traffic protection
- 微服务架构-服务注册中心和服务网关(6.8) (转载)
- 数据库故障容错之系统时钟故障
- Record the processing process of CEPH two RBDS that cannot be deleted
猜你喜欢

C# 导入Excel文件数据的几种方法

Re12: read these3 semantic self segmentation for abstract summary of long legal documents in low

Re12:读论文 Se3 Semantic Self-segmentation for Abstractive Summarization of Long Legal Documents in Low

Realize the reset function of steering wheel UI with touch rotation and finger departure in unity

DGL Chapter 1 (official tutorial) personal notes

总数据量超万亿行,玉溪卷烟厂通过正确选择时序数据库轻松应对

Unity shader uses rendered texture to achieve glass effect

Unity shader procedural texture
![[deep learning]: introduction to pytorch to project practice: simple code to realize linear neural network (with code)](/img/19/18d6e94a1e0fa4a75b66cf8cd99595.png)
[deep learning]: introduction to pytorch to project practice: simple code to realize linear neural network (with code)

HTAP是有代价的
随机推荐
Technology sharing | how to recover the erroneously deleted table and the data in the table?
如何在构建阶段保护镜像安全
负整数及浮点数的二进制表示
Question making note 3 (two point search)
综合设计一个OPPE主页--页面的售后服务
Question note 4 (the first wrong version, search the insertion position)
全链路灰度在数据库上我们是怎么做的?
Atcoder beginer contest 240 g.reporting Takahashi (classical problems of Combinatorial Mathematics)
Leetcode 2022.04.10 China Merchants Bank special competition D. store promotion (DP)
Facet experience -- the development side of dragon game client
CNSA与CASC和CASIC的区别
Code implementation additive attention
Detailed steps for setting up SUSE storage6 environment – win10 + VMware Workstation
2022牛客多校第二场CDE
Huawei mate 40 series exposure: large curvature hyperboloid screen, 5nm kylin 1020 processor! There will also be a version of Tianji 1000+
Round 1A 2022 - Code jam 2022 c.weightlifting (interval DP)
Round 1C 2022 - Code jam 2022 b.square (Mathematics, thinking)
The 16th program design competition of Dalian University of Technology (Problem Solver)
Applet: scroll view slides to the bottom by default
Question making note 2 (add two numbers)