DataList的綁定和分頁

書   名: <%# Eval("Book_Name") %>
作   者: <%# Eval("Book_author")%>
出版社: <%# Eval("PublishName")%>
售   價: <%# string.Format("{0:c2}",Eval("Book_SalePrice")) %>
會員價: <%# string.Format("{0:c2}",Eval("Book_VIPPrice")) %>


當前第[]頁   共[]頁   首頁   上一頁   下一頁   末頁 後臺代碼: //綁定在點擊“各種類別書籍”時,顯示相對應的書籍列表 其中DAL層的 GetList 方法爲: public DataSet GetList(string strWhere) { StringBuilder strSql = new StringBuilder(); strSql.Append("SELECT dbo.Books.*,Book_Price*Book_VIPPrice*0.01 as VIPPrice, dbo.BookPublishing.PublishName FROM dbo.BookPublishing INNER JOIN dbo.Books ON dbo.BookPublishing.PublishID = dbo.Books.PublishID"); if (strWhere.Trim() != "") { strSql.Append(" where " + strWhere); } return DbHelperSQL.Query(strSql.ToString()); } 在後臺編寫的方法: private void bindDatalist1(string typeid) { BLL.Books books = new BLL.Books(); DataSet ds = books.GetList(" Type_ID='" + typeid + "' "); int curPage = Convert.ToInt32(this.lbl_CurPage.Text); PagedDataSource pds = new PagedDataSource(); pds.DataSource = ds.Tables[0].DefaultView; pds.CurrentPageIndex = curPage - 1; pds.PageSize = 5; pds.AllowPaging = true; this.LinkButton1.Enabled = true; this.LinkButton2.Enabled = true; this.LinkButton3.Enabled = true; this.LinkButton4.Enabled = true; if (curPage == 1) { this.LinkButton1.Enabled = false; this.LinkButton2.Enabled = false; } if (curPage == pds.PageCount) { this.LinkButton3.Enabled = false; this.LinkButton4.Enabled = false; } this.lbl_PageCount.Text = pds.PageCount.ToString(); this.DataList1.DataSource = pds; this.DataList1.DataKeyField = "Book_ISBN"; this.DataList1.DataBind(); } //首頁 protected void LinkButton1_Click(object sender, EventArgs e) { this.lbl_CurPage.Text = "1"; condition(); } //上一頁 protected void LinkButton2_Click(object sender, EventArgs e) { this.lbl_CurPage.Text = (Convert.ToInt32(this.lbl_CurPage.Text) - 1).ToString(); condition(); } //下一頁 protected void LinkButton3_Click(object sender, EventArgs e) { this.lbl_CurPage.Text = (Convert.ToInt32(this.lbl_CurPage.Text) + 1).ToString(); condition(); } //末頁 protected void LinkButton4_Click(object sender, EventArgs e) { this.lbl_CurPage.Text = this.lbl_PageCount.Text; condition(); } 二. 在文本框輸入要跳轉的頁數,點擊掉轉到該頁: 跳轉 //TextBox 內輸入所要跳轉的頁: TextBox tx = (TextBox)(this.GridView1.BottomPagerRow.FindControl("TextBox1")); LinkButton tiaoZhuan = (LinkButton)(this.GridView1.BottomPagerRow.FindControl("LinkButton5")); tiaoZhuan.CommandArgument = tx.Text.Trim(); 三. 當前頁/總頁數 的另一種寫法: /
發佈了29 篇原創文章 · 獲贊 0 · 訪問量 5萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章