• repeater控件分页


    写了下repeater控件的用法,还有点问题,AspNetPager 的RecordCount属性用的是得到所有的信息,这样就违背了分页的初衷了,因为自己偷了个懒,懒的在数据访问层写方法了

       ///<summary>
    /// 页面加载
    ///</summary>
    ///<param name="sender"></param>
    ///<param name="e"></param>
    protected void Page_Load(object sender, EventArgs e)
    {
    if (!IsPostBack)
    {
    this.AspNetPager1.RecordCount = NewsBLL.getNews().Count;
    BindData();
    }
    }

    ///<summary>
    /// 给repeater绑定数据
    ///</summary>
    private void BindData()
    {
    this.rptNewsList.DataSource = NewsBLL.getNewsPage(this.AspNetPager1.PageSize, this.AspNetPager1.CurrentPageIndex);
    this.rptNewsList.DataBind();
    }

    ///<summary>
    /// 页改变时
    ///</summary>
    ///<param name="sender"></param>
    ///<param name="e"></param>
    protected void AspNetPager1_PageChanged(object sender, EventArgs e)
    {
    BindData();
    }
            ///<summary>
    /// 分页获取所有新闻信息
    ///</summary>
    ///<param name="pageSize">每页显示条数</param>
    ///<param name="pageIndex">当前页数</param>
    public static DataTable NewsSelectPager(int pageSize, int pageIndex)
    {
    string sqlText = "SELECT News.NewsId AS NewsId, News.NewsTitle AS NewsTitle, News.NewsAuthor AS NewsAuthor, News.NewsDate AS NewsDate, News.NewsContent AS NewsContent, News.NewsClick AS NewsClick, NewsType.NewsTypeId AS NewsTypeId, NewsType.NewsTypeContent AS NewsTypeContent FROM News join NewsType on News.NewsType=NewsType.NewsTypeId";
    SqlDataAdapter da = new SqlDataAdapter(sqlText, DB.conn);
    DataSet ds = new DataSet();
    da.Fill(ds, pageSize * (pageIndex - 1), pageSize, "temptbl");
    DataTable dt = ds.Tables["temptbl"];
    return dt;
    }
    基本上是在网上看的和自己总结的
  • 相关阅读:
    mysql复制那点事
    全排列问题
    56. Merge Interval
    2. Add Two Numbers
    20. Valid Parentheses
    121. Best Time to Buy and Sell Stock
    120. Triangle
    96. Unique Binary Search Trees
    91. Decode Ways
    72. Edit Distance
  • 原文地址:https://www.cnblogs.com/Kiss920Zz/p/2234193.html
Copyright © 2020-2023  润新知