前台代碼 Html
<script type="text/Javascript">
function pager(fullUrl,currentPage,maxPage)
...{
document.write("<font style=''font-family:宋體;font-size:9pt;''>");
if (currentPage==1)...{
document.write("<font color=''#aaaaaa''><font style=''font-family:webdings''>9</font> ");
document.write("<font style=''font-family:webdings''>7</font></font> <b>");
}else...{
document.write("<a href=''?" + fullUrl + "currentpage=1''><font style=''font-family:webdings''>9</font></a> ");
document.write("<a href=''?" + fullUrl + "currentpage=" + (currentPage-1) + "''><font style=''font-family:webdings''>7</font></a> <b>");
}
var i;
var j;
var k;
if (currentPage-5<1)...{
j=1;
}else...{
j=currentPage-5;
}
if (currentPage+5<maxPage)...{
k=currentPage+5;
}else...{
k=maxPage;
}
for(i=j;i<k+1;i++)...{
if (currentPage==i)...{
document.write("<font color=''red''>" + i + "</font> ");
}else...{
document.write("<a href=''?" + fullUrl + "currentpage=" + i +"''>" + i + "</a> ");
}
}
if (currentPage==maxPage)...{
document.write("</b><font color=''#aaaaaa''><font style=''font-family:webdings''>8</font> ");
document.write("<font style=''font-family:webdings''>:</font></font>") ;
}else ...{
document.write("</b><a href=''?" + fullUrl + "currentpage=" + (currentPage +1) + "''><font style=''font-family:webdings''>8</font></a> ");
document.write("<a href=''?" + fullUrl + "currentpage=" + maxPage + "''><font style=''font-family:webdings''>:</font></a>");
}
document.write("</font>");
}
</script>
後台綁定代碼
protected void bindDatalist()
...{
int currentPage = 1;
if (Request.QueryString["currentpage"] != null)
...{
try
...{
currentPage = Convert.ToInt32(Request.QueryString["currentpage"]);
}
catch
...{
currentPage = 1;
}
}
int rowsPerPage = 10;
string sql = "select count(*) from per_info where per_check=1";
int rowsTotal = (int)LiTianPing.DBUtility.DbHelperSQL.GetSingle(sql);
int maxPage = 1;
if (rowsTotal % rowsPerPage == 0)
...{
maxPage = (int)rowsTotal / rowsPerPage;
}
else
...{
maxPage = (int)rowsTotal / rowsPerPage + 1;
}
if (maxPage == 0)
...{
maxPage = 1;
}
if (currentPage < 1)
...{
currentPage = 1;
}
else if (currentPage > maxPage)
...{
currentPage = maxPage;
}
pager.Text = "<script language=''Javascript''>pager(''''," + currentPage.ToString() + "," + maxPage.ToString() + ");</script>";
if (rowsTotal != 0)
...{
if (currentPage == 1)
...{
sql = "select top " + rowsPerPage.ToString() + " id,per_photoname,per_name,per_age,per_work,per_type,per_something,per_danwei,per_nuber from per_info where per_check=1 order by per_nuber desc";
}
else
...{
sql = "select top " + rowsPerPage.ToString() + " id,per_name,per_photoname,per_age,per_work,per_type,per_something,per_danwei,per_nuber from per_info where per_check=1 and id not in (select top " + ((currentPage - 1) * rowsPerPage).ToString() + " id from per_info where per_check=1 order by per_nuber desc) order by per_nuber desc";
//sql = "select top " + rowsPerPage.ToString() + " * from zuoyue_ask where ask_state=1 and id not in (select top " + ((currentPage - 1) * rowsPerPage).ToString() + " N_id from zuoyue_ask where N_id order by N_news_time desc) order by N_news_time desc";
}
DataSet ds = LiTianPing.DBUtility.DbHelperSQL.Query(sql);
ds.Tables[0].Columns.Add("itmno");
int rowcount = ds.Tables[0].Rows.Count;
for (int i = 0; i < rowcount; i++)
...{
ds.Tables[0].Rows[i]["itmno"] = i +((currentPage-1)*10) + 1;
}
DataList1.DataSource = ds.Tables[0].DefaultVIEw;
DataList1.DataBind();
}
//runTime.Text = DateTime.Now.TimeOfDay.Subtract(startTime).TotalMilliseconds.ToString();
//conn.Close();
}