C# 分页类

public static string settitles(string classid, int pageindex, int pagecount, int showcharnum, string isCreate) { string sqlText = ""; if (classid.IndexOf("|") > 0) { sqlText = "select top " + pagecount + " ID,Title,Title1,directoryName,UpdateTime from viw_article_spclassid where pass=1 and Deleted=0 and SpecialID in( " + classid.TrimEnd('|') + ") order by Stars ASC,UpdateTime DESC "; } else { sqlText = "select top " + pagecount + " * from viw_article_spclassid where pass=1 and Deleted=0 and ID not in(select top " + (pagecount * pageindex) + " ID from viw_article_spclassid where pass=1 and Deleted=0 and ClassID in(" + classid + ") order by Hits,ID desc) and ClassID in(" + classid + ") ORDER BY Hits ASC,UpdateTime DESC"; } //System.Web.HttpContext.Current.Response.Write(sqlText); DataSet CalssDS = new BaseClass().ReturnDataSet(sqlText); String resultStr = ""; if (CalssDS == null || CalssDS.Tables[0].Rows.Count == 0) { return "没有记录!"; } else { //判断是否新打开一界面 isCreate = isCreate == "1" ? "" : "target=_blank"; //查看前面是否要图片或特殊字符 for (int i = 0; i < CalssDS.Tables[0].Rows.Count; i++) { string updateTime = CalssDS.Tables[0].Rows[i]["UpdateTime"].ToString(); string[] Str; Str = updateTime.Split('-'); string directoryNameStr = CalssDS.Tables[0].Rows[i]["directoryName"].ToString(); string[] Str2; Str2 = Str[2].Split(' '); //ID位数不够6位前面补零 string id = MyText.TextString.GetID6WeiString(CalssDS.Tables[0].Rows[i]["ID"].ToString()); string time_ID = Str[0] + Str[1] + Str2[0] + id; String time = DateTime.Parse(updateTime).ToString(); string title = ""; //切割文章标题 title += TrimStr(CalssDS.Tables[0].Rows[i]["Title1"].ToString(), showcharnum); resultStr += "

  • " + "" + title + "" + "
  • "; } } return resultStr; } /// 总记录数 /// 每页记录数 /// 当前页数 /// Url参数 /// 返回一个带HTML代码的分页样式(字符串) public static string Pagination(int total, int per, int page, string query_string, string classid, string channelname) { int allpage = 0; int next = 0; int pre = 0; int startcount = 0; int endcount = 0; string pagestr = ""; if (page < 1) { page = 1; } //计算总页数 if (per != 0) { allpage = (total / per); allpage = ((total % per) != 0 ? allpage + 1 : allpage); allpage = (allpage == 0 ? 1 : allpage); } next = page + 1; pre = page - 1; startcount = (page + 5) > allpage ? allpage - 9 : page - 4;//中间页起始序号 //中间页终止序号 endcount = page < 5 ? 10 : page + 5; if (startcount < 1) { startcount = 1; } //为了避免输出的时候产生负数,设置如果小于1就从序号1开始 if (allpage < endcount) { endcount = allpage; }//页码+5的可能性就会产生最终输出序号大于总页码,那么就要将其控制在页码数之内 pagestr = "共" + allpage + "页/第" + page + "页 "; pagestr += page > 1 ? "首页 上一页" : "首页 上一页"; //中间页处理,这个增加时间复杂度,减小空间复杂度 for (int i = startcount; i <= endcount; i++) { pagestr += page == i ? " " + i + "" : " " + i + ""; } pagestr += page != allpage ? " 下一页 末页" : " 下一页 末页"; return pagestr; } /// /// 截取字符串 /// /// 要截取的字符串 /// 长度 /// 截取后的字符串 protected static string TrimStr(string TrimTitle, int TrimLength) { string Trimend = ""; if (TrimTitle.Trim().Length > TrimLength) { Trimend = TrimTitle.Substring(0, TrimLength); } else { Trimend = TrimTitle; } return Trimend; }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值