码迷,mamicode.com
首页 > Web开发 > 详细

分页技术方法AspNetPage

时间:2014-10-03 19:53:55      阅读:262      评论:0      收藏:0      [点我收藏+]

标签:io   os   ar   sp   c   on   cti   r   ad   

 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>

分页技术方法AspNetPage

标签:io   os   ar   sp   c   on   cti   r   ad   

原文地址:http://www.cnblogs.com/DavidVSmary/p/4005217.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!