62,046
社区成员
发帖
与我相关
我的任务
分享
function gjz()
{
var sk = document.getElementById('txtInfo').value;
window.location.href = "ShowKeyWord.aspx?txtNameBook='" + encodeURIComponent (sk) +"'&page=1";
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
int pageIndex = 1; //显示第一条记录
int pageSize = 2; //每页显示几条记录
int PageItem = 5;
int toatalCountRecord = 0;
if (Request.QueryString["page"] == null)
{
pageIndex = 1;
}
else
{
pageIndex = Int32.Parse(Request.QueryString["page"]);
}
string txtNameBook = Request.QueryString["txtNameBook"].ToString();
DataSet ds = this.GetPage(pageIndex, pageSize, txtNameBook, out toatalCountRecord);
Repeater1.DataSource = ds;
Repeater1.DataBind();
//string strWhere = "txtNameBook=" + System.Web.HttpUtility.UrlEncode(nbk.ToString(),Encoding.Default);
string strWhere = "txtNameBook=" + txtNameBook.ToString();
this.BuildPages(toatalCountRecord, pageSize, pageIndex, PageInfo, strWhere);
}
}
public void BuildPages(int ToatalCountRecord, int PageItem, int CurrentPage, HtmlGenericControl PageInfo, string strWhere) {
int Step = 5;//偏移量
int LeftNum = 0;//左界限
int RightNum = 0;//右界限
string PageUrl = HttpContext.Current.Request.FilePath;
int PageCount = (int)Math.Ceiling((double)(ToatalCountRecord) / PageItem);
if (CurrentPage - Step < 1)
{
LeftNum = 1;
}
else
{
LeftNum = CurrentPage - Step;
}
if (CurrentPage + Step > PageCount)
{
RightNum = PageCount;
}
else
{
RightNum = CurrentPage + Step;
}
string OutPut = "";
if (strWhere != null)
strWhere = "&" + strWhere;
OutPut += "<a href='" + PageUrl + "?page=1" + strWhere + "' mce_href='" + PageUrl + "?page=1" + strWhere + "'>" + "首页" + "</a>";
if (CurrentPage > 1)
{
OutPut += " <a href='" + PageUrl + "?page=" + (CurrentPage - 1) + strWhere + "' mce_href='" + PageUrl + "?page=" + (CurrentPage - 1) + strWhere + "'>" + "上一页" + " </a>";
}
if (CurrentPage == 1)
{
OutPut += " 上一页 ";
}
for (int i = LeftNum; i <= RightNum; i++)
{
if (i == CurrentPage)
{
OutPut += " " + "[" + i.ToString() + "]" + "";
}
else
{
OutPut += " <a href='" + PageUrl + "?page=" + i.ToString() + strWhere + "' mce_href='" + PageUrl + "?page=" + i.ToString() + strWhere + "'>" + " " + "[" + i.ToString() + "]" + " " + " </a>";
}
}
if (CurrentPage < PageCount)
{
OutPut += " <a href='" + PageUrl + "?page=" + (CurrentPage + 1) + strWhere + "' mce_href='" + PageUrl + "?page=" + (CurrentPage + 1) + strWhere + "'>" + "下一页" + " </a>";
}
if (CurrentPage == PageCount)
{
OutPut += " 下一页 ";
}
int last;
if (ToatalCountRecord % PageItem == 0)
last = ToatalCountRecord / PageItem;
else
last = ToatalCountRecord / PageItem + 1;
OutPut += "<a href='" + PageUrl + "?page=" + last + strWhere + "' mce_href='" + PageUrl + "?page=" + last + strWhere + "'>" + "末页" + "</a>";
PageInfo.InnerHtml = OutPut;
}