当前位置:编程学习 > C#/ASP.NET >>

需要完整数字分页显示代码,如<<< 1 2 3 4 >>>> 不管是用在asp.net还是一般网页都可以

答案:/// <summary> /// 计算分页字符串 新版本分页 何先念 2011-04-19 09:50:09 /// </summary> /// <param name="Row">总的记录数据</param> /// <param name="PageSize">每页的记录数据</param> /// <param name="PageCurNum">当前页码索引</param> /// <returns>分页字符串</returns> public static string GetTopPageStringA(int Row, int PageSize, int PageCurNum, string ntype) { string pagestr = ""; int PageNum; if (Row % PageSize == 0) PageNum = Row / PageSize; else PageNum = Row / PageSize + 1; string stmp = "<div class=\"rs\" >共" + PageNum.ToString() + "页</div>"; string sLeftstr = ""; string sRightstr = ""; if (PageCurNum == 0) { sLeftstr = "<a class=\"Prev\" >首页</a>"; sRightstr = "<a class=\"Next\" href=\"?ntype=" + ntype.ToString() + "&PageNum=" + Convert.ToString(PageNum - 1) + "\" >末页</a>"; } else if (PageCurNum == (PageNum - 1)) { sLeftstr = "<a class=\"Prev\" onclick href=\"?ntype=" + ntype.ToString() + "&PageNum=0\">首页</a>"; sRightstr = "<a class=\"Next\" >末页</a>"; } else { sLeftstr = "<a class=\"Prev\" href=\"?ntype=" + ntype.ToString() + "&PageNum=0\" >首页</a>"; sRightstr = "<a class=\"Next\" href=\"?ntype=" + ntype.ToString() + "&PageNum=" + Convert.ToString(PageNum - 1) + "\">末页</a>"; } if (PageNum < 5) { for (int i = 0; i < PageNum; i++) { if (i == PageCurNum) pagestr += "<a class=\"this-page\">" + Convert.ToString(i + 1) + "</a>"; else pagestr += "<a href=\"?ntype=" + ntype.ToString() + "&PageNum=" + i.ToString() + "'\" >" + Convert.ToString(i + 1) + "</a>"; } return sLeftstr + pagestr + sRightstr + stmp; } if (PageCurNum >= 2 && PageCurNum + 2 < PageNum) { for (int i = PageCurNum - 2; i <= PageCurNum + 2; i++) { if (i == PageCurNum) pagestr += "<a class=\"this-page\" >" + Convert.ToString(i + 1) + "</a>"; else pagestr += "<a href=\"?ntype=" + ntype.ToString() + "&PageNum=" + i.ToString() + "\">" + Convert.ToString(i + 1) + "</a>"; } } else if (PageCurNum > PageNum - 3) { for (int i = PageNum - 5; i <= (PageNum - 1); i++) { if (i == PageCurNum) pagestr += "<a class=\"this-page\">" + Convert.ToString(i + 1) + "</a>"; else pagestr += "<a href=\"?ntype=" + ntype.ToString() + "&PageNum=" + i.ToString() + "\">" + Convert.ToString(i + 1) + "</a>"; } } else { for (int i = 0; i < 5; i++) { if (i == PageCurNum) pagestr += "<a class=\"this-page\">" + Convert.ToString(i + 1) + "</a>"; else pagestr += "<a href=\"?ntype=" + ntype.ToString() + "&PageNum=" + i.ToString() + "\">" + Convert.ToString(i + 1) + "</a>"; } } return sLeftstr + pagestr + sRightstr + stmp; }
其他:给个Email我发几个样式的给你瞅瞅 ''strUrl:链接
''page_num:一共多少面
''page_cur:当前第几页
''page_per:显示多少页
function dis_page_num(strUrl,page_num,page_cur,page_per)
	page_num_st=get_page_num_st(page_num,page_cur,page_per)
	page_num_end=get_page_num_end(page_num,page_cur,page_per)
	str_page=""
	for i=page_num_st to page_num_end
		if i=page_cur then
			str_page=str_page & "<a href=""" & strUrl & """ style='color:red'>" & i & "</a> "
		else
			str_page=str_page & "<a href=""" & strUrl & """>" & i & "</a> "
		end if
	next
	dis_page_num=str_page
end function
function get_page_num_st(page_num,page_cur,page_per)
	page_per_half=int(page_per/2)
	pev=page_cur-page_per_half
	if page_per>=page_num then
		tep=1
	else
		if page_per_half+1>=page_cur then
			tep=1
		else
			if page_num-page_per<pev then
				tep=page_num-page_per+1
			else
				tep=page_cur-page_per_half
			end if
		end if
	end if
	get_page_num_st=tep
end function
function get_page_num_end(page_num,page_cur,page_per)
	page_per_half=int((page_per-1)/2)
	if page_per>=page_num then
		tep=page_num
	else
		if page_cur+page_per_half>=page_num then
			tep=page_num
		else
			if page_cur+page_per_half<=page_per then
				tep=page_per
			else
				tep=page_cur+page_per_half
			end if
		end if
	end if
	get_page_num_end=tep
end function
''test
Response.Write(dis_page_num("list_pro.asp",10,1,10)) 

上一个:请教一个问题:ASP文件中将数据库表内容导成txt文件.
下一个:下面是一段Chklogin.asp的代码,但是测试时它出现问题了

CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,