关闭

repeater pageDataSource 分页

306人阅读 评论(0) 收藏 举报

protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindDataByPage();
        }
    }
    void BindDataByPage()
    {
        int currentPage = 1;
        if (this.PageNum.Text != "")
            currentPage = Convert.ToInt32(PageNum.Text);
        string sql = "SELECT * FROM _article ";
        chuanData.ConString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("App_Data") + "/data.mdb";
        //新建分页对象实例
        PagedDataSource pds = new PagedDataSource();
        pds.DataSource = chuanData.DataTable(sql).DefaultView;
        pds.AllowPaging = true;
        pds.PageSize = 4;

        //总页数
        this.PageCount.Text = pds.PageCount.ToString();
        //由于页码索引从零开始,则执行减一操作
        pds.CurrentPageIndex = currentPage - 1;

        btnFirst.Enabled = true;
        btnFront.Enabled = true;
        btnNext.Enabled = true;
        btnLast.Enabled = true;

        if (currentPage == 1)
        {
            btnFront.Enabled = false;
            btnFirst.Enabled = false;
        }

        if (currentPage == pds.PageCount)
        {
            btnNext.Enabled = false;
            btnLast.Enabled = false;
        }

        Repeater1.DataSource = pds;
        Repeater1.DataBind();

    }

    //向前翻页操作事件
    public void btnFront_Click(object sender, System.EventArgs e)
    {
        PageNum.Text = Convert.ToString(Convert.ToInt32(PageNum.Text) - 1);
        BindDataByPage();
    }

    //选定至第一页操作事件
    public void btnFirst_Click(object sender, System.EventArgs e)
    {
        PageNum.Text = "1";
        BindDataByPage();
    }

    //下一页事件
    public void btnNext_Click(object sender, System.EventArgs e)
    {
        PageNum.Text = Convert.ToString(Convert.ToInt32(PageNum.Text) + 1);
        BindDataByPage();
    }

    //最后一页选定事件
    public void btnLast_Click(object sender, System.EventArgs e)
    {
        PageNum.Text = Convert.ToString(Convert.ToInt32(PageCount.Text));
        BindDataByPage();
    }

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:439559次
    • 积分:4307
    • 等级:
    • 排名:第7008名
    • 原创:39篇
    • 转载:106篇
    • 译文:0篇
    • 评论:26条
    文章分类
    最新评论