zoukankan      html  css  js  c++  java
  • 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;
    }
    基本上是在网上看的和自己总结的
  • 相关阅读:
    POJ 2342.Anniversary party-树形dp
    Codeforces Round #363 (Div. 2) A、B、C
    Codeforces Beta Round #17 D.Notepad 指数循环节
    hdu 5920 Wool 思路
    hdu 5719 Arrange 贪心
    hdu 5718 Oracle 高精度
    hiho #1332 : 简单计算器 栈+递归
    UESTC 1074 秋实大哥搞算数 栈模拟
    cdoj 1329 卿学姐与魔法 优先队列
    cdoj 1324 卿学姐与公主 线段树裸题
  • 原文地址:https://www.cnblogs.com/Kiss920Zz/p/2234193.html
Copyright © 2011-2022 走看看