110,539
社区成员
发帖
与我相关
我的任务
分享
protected void Page_Load(object sender, EventArgs e)
{
string keywords =Request.QueryString["keywords"];//关键字
int totalcount;//总记录数
int currentpage = 1;//当前页
int PageSize = 5;//分页大小
....
//计算总页数;totalpage
int totalpage = 0;
if (totalcount / PageSize == 0)
{
totalpage = totalcount / PageSize;
}
else
{
totalpage = totalcount / PageSize + 1;
}
//判断page
if (string.IsNullOrEmpty(Request.QueryString["page"]) || judgeType.isNumber(Request.QueryString["page"]) == false)
{
currentpage = 1;
}
else
{
int tempPageIndex = Convert.ToInt32(Request.QueryString["page"]);
if (tempPageIndex <= 0)
{
currentpage = 1;
}
else if (tempPageIndex > totalpage)
{
currentpage = totalpage;
}
}
aManage.SetArticleList("articleSearchPage", cid, PageSize, currentpage, keywords);//搜索新闻
}
judgeType 类
public class judgeType
{
public judgeType()
{
}
/// <summary>
/// 判断是否为正整数
/// </summary>
/// <param name="strValue"></param>
/// <returns>是正整数返回true,不是返回false</returns>
public static bool isNumber(string strValue)
{
Regex regex = new Regex("^[0-9]*[1-9][0-9]*$");
return regex.IsMatch(strValue.Trim());
}
}
if (Request.QueryString["page"] == null)
{
currentpage = 1;
}
else
{
//判断是否为数值
if (judgeType.isNumber(Request.QueryString["page"]) == false)
{
currentpage = 1;
}
else // 是数值
{
if (Convert.ToInt32(Request.QueryString["page"]) > totalpage) //是否大于总页数
{
currentpage = totalpage;
}
else
{
currentpage = Convert.ToInt32(Request.QueryString["page"]);
}
}
}
if (string.IsNullOrEmpty(Request.QueryString["page"]) || !judgeType.isNumber(Request.QueryString["page"]))
//判断page
if (string.IsNullOrEmpty(Request.QueryString["page"]) )
{
currentpage = 1;//为空
}
else
{
if(judgeType.isNumber(Request.QueryString["page"]) == false)
currentpage = 1;//不为空但不是整数
int tempPageIndex = Convert.ToInt32(Request.QueryString["page"]);
//......