用AspNetPager.dll进行分页

1.表示层,引用->添加引用->浏览->/bin/AspNetPager.dll确定

2.default.aspx
<%@ Register Assembly="AspNetPager" Namespace="Wuqi.Webdiyer" TagPrefix="webdiyer" %>


<%#Eval("id")%><%#Eval("GuestName")%><%#Eval("GuestEmail")%><%#Eval("content")%>


FirstPageText="首页" LastPageText="末页" NextPageText="下页" PrevPageText="上页" Font-Names="Arial" BackColor="#EDEDED" AlwaysShow="true"   SubmitButtonText="跳转" SubmitButtonStyle="botton" OnPageChanging="AspNetPager1_PageChanging1" HorizontalAlign="Right" >

3.default.aspx.cs

    public partial class Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack){
                bind();
            }
        }

        private void bind()
        {   /把记录总数赋值给分页控件
            string sql = "select [id],[GuestName],[GuestEmail],[Content],[Time],[Reply] from [Tmessage] order by id desc";
            DataSet ds = ACCHelper.ExecuteDataset(ACCHelper.ConnectionStringLocalTransaction, CommandType.Text, sql, null);
            AspNetPager1.RecordCount = ds.Tables[0].Rows.Count;
            int pageSize = AspNetPager1.PageSize = 6;
            int pageIndex =AspNetPager1.CurrentPageIndex - 1;
            绑定当前页的数据到Repeater控件
            DataSet dd = GVBind(sql,pageIndex,pageSize);
            myRepeater.DataSource = dd;
            myRepeater.DataBind();
        }
        //PageChanged事件处理
        protected void AspNetPager1_PageChanging1(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
        { AspNetPager1.CurrentPageIndex = e.NewPageIndex; bind(); }

        //返回当前页dataset
        public static DataSet GVBind(string sqlstring, int page_index, int page_size)
        {
            int firstPage = page_index * page_size;
            OleDbConnection myCon = new OleDbConnection(ACCHelper.ConnectionStringLocalTransaction);
            DataSet ds = new DataSet();
            OleDbDataAdapter myConAdp = new OleDbDataAdapter(sqlstring, myCon);
            myConAdp.Fill(ds, firstPage, page_size, "article");
            myCon.Close();
            return ds;
        }
    }

你可能感兴趣的:(c#代码)