分页技术方法AspNetPage

 private void bind()  {            

    AspNetPager1.RecordCount = getCount();            

    AspNetPager1.PageSize = 5;            

     string sql = "select * from Books";            

     SqlDataAdapter da = new SqlDataAdapter(sql, ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString);            

    DataTable dt = new DataTable();            

    da.Fill((AspNetPager1.CurrentPageIndex - 1) * AspNetPager1.PageSize, AspNetPager1.PageSize, dt);            

     Repeater1.DataSource = dt.DefaultView;            

    Repeater1.DataBind();  

}

 

 

 private int getCount()  {            

    string sql = "select count(*) from Books";

            using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString))            

     {                

        SqlCommand cmd = new SqlCommand(sql,conn);                

        conn.Open();                

        int num = Convert.ToInt32(cmd.ExecuteScalar());                

        conn.Close();                

        return num;            

      }  

}

 

  protected void AspNetPager1_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)  

  {            

        AspNetPager1.CurrentPageIndex = e.NewPageIndex;            

        bind();  

  }

 

 

 

  <webdiyer:AspNetPager ID="AspNetPager1" runat="server"            

  FirstPageText="首页" LastPageText="末页" NextPageText="下一页" NumericButtonCount="5"            

  onpagechanging="AspNetPager1_PageChanging" PageIndexBoxType="DropDownList"            

  PageSize="5" PrevPageText="上一页" ShowCustomInfoSection="Left"            

  ShowPageIndexBox="Always" >  

 

</webdiyer:AspNetPager>

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。