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(); 三. 当前页/总页数 的另一种写法: /
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值