导航

« 开启AHCI后找不到(固态)硬盘的解决方法抠图小技巧  »

Aspnetpager如何用在Access中结合Repeater

虚位以待 Csharp

Aspnetpager官方介绍的主要是用于sql的例子,很多时候我们需要用到Access数据库(没有存储过程),所以必需另外探索了,在网上找了一段时候后总结如下:

1.先下载Aspnetpager.dll 文件

地址:http://www.webdiyer.com/aspnetpager/downloads/ ,然后复制到bin目录下,再在vs中添加引用

2.前台中(aspx),把控件拖到  Repeater的外面,以下是代码片断,其中很多参数可以在控件中自定义

                 ......

                </tr> 
                  </ItemTemplate>  </asp:Repeater>
                 </table>

     <webdiyer:AspNetPager ID="AspNetPager1" runat="server"
                        onpagechanged="AspNetPager1_PageChanged1"
                        CurrentPageButtonPosition="Beginning"
                        CustomInfoHTML="第%CurrentPageIndex%页,共%PageCount%页,每页%PageSize%条" FirstPageText="首页"
                        LastPageText="尾页" NextPageText="下一页" PrevPageText="上一页"
                        ShowCustomInfoSection="Left" ShowPageIndexBox="Always" SubmitButtonText="Go"
                        TextAfterPageIndexBox="页" TextBeforePageIndexBox="转到" PageSize="10"
                        UrlPaging="True" AlwaysShow="True" ShowNavigationToolTip="True" >
        </webdiyer:AspNetPager>

                .......

3.后台中(cs)

        protected void Page_Load(object sender, EventArgs e)
        {

            if (!IsPostBack)
            {
 
                BindData();
            }

         
        }
 

 

        private void BindData()
        {


            OleDbConnection conn = new OleDbConnection(System.Web.Configuration.WebConfigurationManager.ConnectionStrings["connStr"].ConnectionString);
            OleDbCommand command = conn.CreateCommand();
            command.Connection = conn;
            conn.Open();
            command.CommandType = CommandType.Text;
            OleDbDataAdapter ad = new OleDbDataAdapter(command);

            command.CommandText = string.Format("SELECT count(*) FROM Art ");
            AspNetPager1.RecordCount = int.Parse(command.ExecuteScalar().ToString());

            command.CommandText = string.Format("SELECT  *  FROM Art ");
            DataSet ds = new DataSet();
            ad.Fill(ds, AspNetPager1.PageSize * (AspNetPager1.CurrentPageIndex - 1), AspNetPager1.PageSize, "Product");

            conn.Close();
            rptCate.DataSource = ds.Tables[0].DefaultView;
            rptCate.DataBind();

        

        }

        /// <summary>
        /// 查询条件
        /// </summary>
   

        protected void AspNetPager1_PageChanged1(object sender, EventArgs e)
        {
            BindData();
        }

 

 如果看不到图片请看:http://blog.sina.com.cn/s/blog_5c5357aa0101p134.html

 

 

  • 顶一下
虚位以待




原创文章如转载,请注明:转载自落日故乡

本文链接地址:http://www.spersky.com/post/443.html

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

内容搜索


虚位以待

常用链接

最新评论及回复

Powered By Z-Blog

Copyright spersky All Rights Reserved.Theme Moonlight,Calf modified.n 浙ICP备16017820号-1