如题,请各位介绍下 aspnetpager控件的 常用 属性 以及 事件结合Repeater使用...欢迎讨论

解决方案 »

  1.   

    下载一个AspNetPager72Samples,里面就有演示文件。
    事件一般就是AspNetPager1_PageChanged,基本上就是下面这些了/* 分页控件的样式*/
    .anpager .cpb {background:#1F3A87 none repeat scroll 0 0;border:1px solid #CCCCCC;color:#FFFFFF;font-weight:bold;margin:5px 4px 0 0;padding:4px 5px 0;}
    .anpager a {background:#FFFFFF none repeat scroll 0 0;border:1px solid #CCCCCC;color:#1F3A87;margin:5px 4px 0 0;padding:4px 5px 0;text-decoration:none}
    .anpager a:hover{background:#1F3A87 none repeat scroll 0 0;border:1px solid #1F3A87;color:#FFFFFF;}
    -------------------------------------------------------------------------------
    当前页/总页数:<%=AspNetPager1.CurrentPageIndex %>/<%=AspNetPager1.PageCount %>总共:<%=AspNetPager1.RecordCount %>条
    <webdiyer:AspNetPager ID="AspNetPager1" runat="server" OnPageChanged="AspNetPager1_PageChanged"
                    PageSize="10" AlwaysShow="true" CssClass="anpager" CurrentPageButtonClass="cpb"
                    FirstPageText="首页" LastPageText="尾页" NextPageText="后页" PrevPageText="前页">
                </webdiyer:AspNetPager>
      

  2.   


    <webdiyer:AspNetPager ID="Pager" 
    runat="server"   
    AlwaysShow="true" 
    CustomInfoHTML=""
    CustomInfoSectionWidth="40%" 
    FirstPageText="首页" 
    LastPageText="尾页" 
    NextPageText="下一页"             
    OnPageChanged="Pager_PageChanged" 
    PageIndexBoxType="DropDownList"  
    PageSize="10"               
    PrevPageText="上一页" 
    ShowCustomInfoSection="Left" 
    ShowPageIndexBox="Always" 
    SubmitButtonText="Go"    
    TextAfterPageIndexBox="" 
    TextBeforePageIndexBox="" 
    UrlPaging="true">
    </webdiyer:AspNetPager>使用很简单
     private void BindInfo()
            {
                Pager.CurrentPageIndex = (Int32)Request.QueryString("page");
                DataSet ds=....//获取数据
                if (ds!=null && ds.Tables[0]!=null && ds.Tables[0].Rows.Count > 0)
                {
                    Pager.RecordCount = ds.Tables[0].Rows.Count ;
                    rpt.DataSource = ds.Tables[0].DefaultView;            }
                else
                {
                    Pager.RecordCount = 0;
                    rpt.DataSource = null;
                }            rpt.DataBind();
            } pager的PageChanged事件中执行 BindInfo方法就行
      

  3.   

    网上有这个控件使用方法...(AspNetPager 分页控件7.2版源代码)
      

  4.   


    PageChanged 事件中要添加绑定repeater的代码 留个邮箱我发你个例子吧
      

  5.   

    顶啊,大家帮忙呀,aspnetpager设置了pagesize,也取出了数据库中总的数据条数,现在怎么样从数据库中取出每页应该显示的是哪些记录呢???
      

  6.   

    (AspNetPager2.CurrentPageIndex - 1) * AspNetPager2.PageSize
      

  7.   

    aspnetpager控件这个控件只是有来显示分页的按钮,可以传入当前页的页码,但每一页的数据还得你去select,用 fill的一个重构函数
    public int Fill(
       DataSet dataSet,
       int startRecord,
       int maxRecords,
       string srcTable
    );就可以了
      

  8.   

    cs文件里首先获得总的记录条数,放在!IsPostBack中
    然后再绑定每页的数据,如定义了BindRpt()
    private void BindRpt()
    {
    DBConn db=new DBConn();
    string sql = "select * from (select a.*, rownum r from (select * from articlecomment order by commentDate desc) a where rownum <= " + AspNetPager2.EndRecordIndex + ") b where r >= " + AspNetPager2.StartRecordIndex;
    Datatable dt = db.ExecuteDatatable(sql);
    Repeater1.DataSource=dt;
    Repeater1.DataBind();
    }protected void AspNetPager2_PageChanged(object sender, EventArgs e)
    {
        BindRpt();
    }注意sql语句(oracle的),如你设置了分页数15,那么每次取出的记录就是15条。
    sqlserver中好像是用top 15这样来分的。。就这么简单
      

  9.   

    发我一个吧、、、[email protected]
      

  10.   


    那你把这个方法拿出来看看呗  我写的是用datareader存数据,做数据源给Repeater  
    public IList<NewsInfo> BindData()
            {
                int CurrentPage = this.AspNetPager1.CurrentPageIndex;
                int PageSize = this.AspNetPager1.PageSize;
                int startIndex = (CurrentPage - 1) * PageSize + 1;
                int endIndex = startIndex + PageSize - 1;
                string sql = string.Format("select * from (select *,row_number() over(order by NewsID desc) as rowNum from News ) as myTable where rowNum between {0} and {1}", startIndex, endIndex);
                SqlConnection connStr = new SqlConnection("Data Source = wq-wq;Initial Catalog = NewsPublish;uid = sa;pwd = 123");
                SqlCommand cmd = new SqlCommand(sql, connStr);
                connStr.Open();
                SqlDataReader sdr = cmd.ExecuteReader();
                while (sdr.Read())
                {
                    NewsInfo newsInfo = new NewsInfo();
                    newsInfo.NewsID = Convert.ToInt32(sdr["NewsID"].ToString());
                    newsInfo.TitleName = sdr["TitleName"].ToString();
                    newsInfo.NewsContent = sdr["NewsContent"].ToString();
                    newsList.Add(newsInfo);
                }
                return newsList;
            }
      

  11.   

    下个demo,里面的实例很详细清楚,一看就懂!