AspNETPager的用法

  1. <html xmlns="http://www.w3.org/1999/xhtml" >
  2. <head runat="server">
  3.     <title>无标题页</title>
  4. </head>
  5. <body>
  6.     <form id="form1" runat="server">
  7.     <div>
  8.         <asp:DataList ID="DataList1" runat="server">
  9.             <ItemTemplate>
  10.                 ProductName:
  11.                 <asp:Label ID="ProductNameLabel" runat="server" Text='<%# Eval("ProductName") %>'>
  12.                 </asp:Label><br />
  13.                 <br />
  14.             </ItemTemplate>
  15.         </asp:DataList>
  16.         <webdiyer:aspnetpager id="pager1" runat="server" OnPageChanging="ChangePage"></webdiyer:aspnetpager>    
  17.     </div>
  18.     </form>
  19. </body>
  20. </html>
后置代码:default.aspx.cs

  1. using System;
  2. using System.Data;
  3. using System.Configuration;
  4. using System.Collections;
  5. using System.Web;
  6. using System.Web.Security;
  7. using System.Web.UI;
  8. using System.Web.UI.WebControls;
  9. using System.Web.UI.WebControls.WebParts;
  10. using System.Web.UI.HtmlControls;
  11. using cpp114.tools.oledb;
  12. using System.Data.OleDb;
  13. using Wuqi.Webdiyer;
  14. public partial class test_Default : System.Web.UI.Page
  15. {
  16.     protected OleDbConnection conn = new OleDbConnection();
  17.     protected OleDbCommand cmd = new OleDbCommand();
  18.     protected void Page_Load(object sender, EventArgs e)
  19.     {
  20.         if (!IsPostBack) {
  21.             initdb();
  22.             conn.Open();
  23.             cmd.CommandText = "select count(*) from t_product";
  24.             pager1.RecordCount = (int)cmd.ExecuteScalar();
  25.             conn.Close();
  26.             BindData();
  27.                        
  28.         }
  29.     }
  30.  //初始化连接对象
  31.     protected void initdb(){
  32.         conn.ConnectionString = oledbtool.myConnStr + Server.MapPath(oledbtool.mydbName);
  33.         cmd.Connection = conn;        
  34.     }
  35.  //数据绑定
  36.     protected void BindData() {
  37.         initdb();
  38.         OleDbDataAdapter sda = new OleDbDataAdapter("select * from t_product",conn);       
  39.         DataSet ds = new DataSet();
  40.         sda.Fill(ds, pager1.PageSize * (pager1.CurrentPageIndex - 1), pager1.PageSize, "temptbl");
  41.         DataList1.DataSource = ds.Tables["temptbl"];
  42.         DataList1.DataBind();
  43.     }
  44.  //翻页事件
  45.     protected void ChangePage(object src, PageChangedEventArgs e)
  46.     {
  47.         pager1.CurrentPageIndex = e.NewPageIndex;
  48.         BindData();
  49.     }    
  50. }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值