转换c#代码,帮我!
function getPageInfo(totalPage,absolutePage){
if(isNaN(totalPage))totalPage=1;
var pgStr= " ";
var has1=absolutePage-5> =1;
var has2=absolutePage+5 <=totalPage;
var begin=end=1;
if(has1 && has2){
begin=absolutePage-4;
end=absolutePage+5;
}else if(!has1 && has2){
begin=1;
end=totalPage> =10?10:totalPage;
}else if(has1 && !has2){
begin=totalPage-9;begin=begin <1?1:begin;
end=totalPage;
}else{
begin=1;
end=totalPage;
}
if(absolutePage> 1){
pgStr+=’ <a href= "demo.asp?page=’+eval(absolutePage-1)+’ "> 上一页 </a> ’;
}else{
pgStr+=’上一页 ’;
}
for(i=begin;i <=end;i++){
pgStr+=’ <a href= "demo.asp?page=’+i+’ "’;
if(i==absolutePage)pgStr+=’ style= "color:red;font-weight:bold "’;
pgStr+=’> [’+i+’] </a> ’;
}
if(absolutePage <totalPage){
pgStr+=’ <a href= "demo.asp?page=’+eval(absolutePage+1)+’ "> 下一页 </a> ’;
}else{
pgStr+=’ 下一页’
}
return pgStr;
}
<%
totalPage=100
absPage=Request.QueryString( "page ")
if not isNumeric(absPage) then absPage=1
absPage=cint(absPage)
//分别自己取得总页数和当前页,存在变量中
//下面调用:
%>
<%=getPageInfo(totalPage,absPage)%>
------解决方案--------------------public string getPageInfo(int totalPage, int absolutePage)
{
if (totalPage <= 0) totalPage = 1;
string pgStr = " ";
bool has1 = absolutePage - 5 > = 1;
bool has2 = absolutePage + 5 <= totalPage;
int begin = 1;
int end = 1;
if (has1 && has2)
{
begin = absolutePage - 4;
end = absolutePage + 5;