请大侠帮忙:不用GridView和AspNetPager等控件,输出纯Div和CSS的分页,要怎么写?
ASPX页面的代码:
<div class="lst_box" id="divNewsList" runat="server"><!--文章列表--></div><div class="page"><a href="/NewsList_1.html">第一页</a><span class="NewsList_2.html">2</span><a href="NewsList_3.html">3</a>/div>
void bindData(string strSortID,string strNewsTitle) { if (ViewState["Sort"] == null) ViewState["Sort"] = "AddDate DESC"; int TotalPage = 0; int TotalRecord = 0; int PageSize = 12; int CurrentPage = 1; //#region 循环分类 DataTable dtBizClass = FrontPageBiz.GetPageNewsListByConditions(1,NewsSortID,SearchKeyWord, PageSize, ref CurrentPage, out TotalPage, out TotalRecord, (string)ViewState["Sort"]); for (int i = 1; i < dtBizClass.Rows.Count; i++) { divNewsList.Controls.Add(new LiteralControl("<div class=\"lstbox_m\"><h3><a href=\"/html/" + dtBizClass.Rows[i]["NewsID"].ToString() + ".html\">" + dtBizClass.Rows[i]["NewsTitle"].ToString() + "</a></h3><p class=\"more_big\">日期:" + string.Format("{0:d}", dtBizClass.Rows[i]["AddDate"]) + " 关注:100 <a href=\"#\">咨询专家</a></p> <p class=\"txt\">" + dtBizClass.Rows[i]["Descriptions"].ToString() + "</p></div>")); }
ALTER PROCEDURE [dbo].[XMLPageNewsListByCondition] ( @vType int, @SortID varchar(12), @NewsTitle varchar(120), @PageSize int, @CurrentPage int output, @TotalPage int output, @TotalRecord int output, @SortBy varchar(100) )AS
//-----分页所使用的变量 private int num = 148; //在页面显示几条信息 private int pageSize = 5; protected void Page_Load(object sender, EventArgs e) { //首次加载 if (!IsPostBack) { DlBooksPage(); } } /// <summary> /// 分页 /// </summary> /// <param name="CurrentPage"></param> private void DataListBind(int CurrentPage) { int pageCount = this.BookNum(); if (CurrentPage < 1) { CurrentPage = 1; } if (CurrentPage > pageCount) { CurrentPage = pageCount; } if (CurrentPage == 1) { this.btnPre.Enabled = false; } if (CurrentPage == pageCount) { this.btnNext.Enabled = false; } this.lblCurrentPage.Text = CurrentPage.ToString(); this.lblPageCount.Text = pageCount.ToString(); //DataSourceID 和 DataSource 不能并存,如果要 rptSearch.DataSource 起作用必须把 DataSourceID 赋为空 if (dlBooks.DataSourceID != null) { dlBooks.DataSourceID = null; } //调用方法 dlBooks.DataSource = BookManager.GetBooksByPageSize(this.GetKey(), pageSize, CurrentPage, this.GetOrder(), this.GetDesc()); //重新绑定数据源 dlBooks.DataBind(); } /// <summary> /// 查询图书的总数 /// </summary> /// <returns></returns> public int BookNum() { int booksNum = BookManager.GetAllBooksTotal(); int pageCount = 0; if (booksNum % pageSize == 0) { pageCount = booksNum / pageSize; } else { pageCount = booksNum / pageSize + 1; } return pageCount; } public void DlBooksPage() { this.DataListBind(this.ReturnCurrentPage()); } //当前页 public int ReturnCurrentPage() { int currentPage = 1; if (Request.QueryString["Page"] != null) { try { currentPage = Convert.ToInt32(Request.QueryString["page"]); } catch { } } if (currentPage < 1) { currentPage = 1; } if (currentPage > this.BookNum()) { currentPage = this.BookNum(); } return currentPage; } //截取字符串,多余内容以“......”显示在页面 public string FormatString(string message) { if (message.Length > num) { return message.Substring(0, num) + "..."; } else { return message; } } //上一页 protected void btnPre_Click1(object sender, EventArgs e) { Response.Redirect(Request.Url.AbsolutePath + "?page=" + (this.ReturnCurrentPage() - 1) + "&order=" + this.GetOrderString() + "&Desc=" + this.GetDescString() + "&key=" + this.GetKey()); } //下一页 protected void btnNext_Click(object sender, EventArgs e) { Response.Redirect(Request.Url.AbsolutePath + "?page=" + (this.ReturnCurrentPage() + 1) + "&order=" + this.GetOrderString() + "&Desc=" + this.GetDescString() + "&key=" + this.GetKey()); } //按出版日期排序 protected void btnDate_Click(object sender, EventArgs e) { //DataSourceID 和 DataSource 不能并存,如果要 rptSearch.DataSource 起作用必须把 DataSourceID 赋为空 if (dlBooks.DataSourceID != null) { dlBooks.DataSourceID = null; } if (this.GetDescString() == "0") { Response.Redirect(Request.Url.AbsolutePath + "?page=" + this.ReturnCurrentPage() + "&order=2&Desc=1"); } else { Response.Redirect(Request.Url.AbsolutePath + "?page=" + this.ReturnCurrentPage() + "&order=2&Desc=0"); } } //按价格排序 protected void btnPrice_Click(object sender, EventArgs e) { //DataSourceID 和 DataSource 不能并存,如果要 rptSearch.DataSource 起作用必须把 DataSourceID 赋为空 if (dlBooks.DataSourceID != null) { dlBooks.DataSourceID = null; } if (this.GetDescString() == "0") { Response.Redirect(Request.Url.AbsolutePath + "?page=" + this.ReturnCurrentPage() + "&order=1&Desc=1"); } else { Response.Redirect(Request.Url.AbsolutePath + "?page=" + this.ReturnCurrentPage() + "&order=1&Desc=0"); } this.DataBind(); } public string GetOrder() { int num = 0; if (Request.QueryString["Order"] != null) { try { num = Convert.ToInt32(Request.QueryString["Order"]); } catch { } } switch (num) { case 0: return "id"; break; case 1: return "UnitPrice"; break; case 2: return "PublishDate"; break; default: return "id"; } } public string GetOrderString() { int num = 0; if (Request.QueryString["Order"] != null) { try { num = Convert.ToInt32(Request.QueryString["Order"]); } catch { } } switch (num) { case 0: return "0"; break; case 1: return "1"; break; case 2: return "2"; break; default: return "0"; } } //获取地址栏 此方法提供给数据库 public string GetDesc() { int num = 0; if (Request.QueryString["Desc"] != null) { try { num = Convert.ToInt32(Request.QueryString["Desc"]); } catch { } } if (num == 0) { return "asc"; } else { return "desc"; } } //此方法提供给地址栏 public string GetDescString() { int num = 0; if (Request.QueryString["Desc"] != null) { try { num = Convert.ToInt32(Request.QueryString["Desc"]); } catch { } } if (num == 0) { return "0"; } else { return "1"; } } public string GetKey() { if (Request.QueryString["key"] != null) { return Request.QueryString["Key"]; } return ""; }
[解决办法]