欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

repeater分页 内容显示

程序员文章站 2022-06-29 18:59:43
using system; using system.collections; using system.componentmodel; us...
using system;
using system.collections;
using system.componentmodel;
using system.data;
using system.drawing;
using system.web;
using system.web.sessionstate;
using system.web.ui;
using system.web.ui.webcontrols;
using system.web.ui.htmlcontrols;
using system.data.oledb;

namespace note
{
    /// <summary>
    /// _default 的摘要说明。
    /// </summary>
    public class _default : system.web.ui.page
    {
        protected system.web.ui.webcontrols.repeater rpt_sword_list;
        protected system.web.ui.webcontrols.label lbl_count;
        protected system.web.ui.webcontrols.label lbl_current_page;
        protected system.web.ui.webcontrols.label lbl_total_page;
        protected system.web.ui.webcontrols.linkbutton lb_frist;
        protected system.web.ui.webcontrols.linkbutton lb_p;
        protected system.web.ui.webcontrols.linkbutton lb_n;
        protected system.web.ui.webcontrols.linkbutton lb_last;

        private void page_load(object sender, system.eventargs e)
        {
            // 在此处放置用户代码以初始化页面
            if(!this.ispostback)
            {
                this.db_bind();
            }
        }

        private void db_bind()
        {
            int ipageindex = convert.toint32(this.lbl_current_page.text);
            oledbconnection conn = dbconn.createconn();
            oledbcommand cmd = new oledbcommand("select * from a where flag=true order by cdate desc",conn);
            oledbdataadapter oda = new oledbdataadapter();
            oda.selectcommand = cmd;
            dataset ds = new dataset();
            oda.fill(ds,"sword_list");
            pageddatasource pds = new pageddatasource();
            pds.datasource = ds.tables["sword_list"].defaultview;
            pds.allowpaging = true;
            pds.pagesize = 5;
            pds.currentpageindex = ipageindex - 1;
            this.lbl_total_page.text = pds.pagecount.tostring();
            this.lbl_count.text = pds.count.tostring();
            this.lb_frist.enabled = true;
            this.lb_p.enabled = true;
            this.lb_n.enabled = true;
            this.lb_last.enabled = true;
            if(this.lbl_current_page.text=="1")
            {
                this.lb_frist.enabled = false;
                this.lb_p.enabled = false;
            }
            if(this.lbl_current_page.text==pds.pagecount.tostring())
            {
                this.lb_n.enabled = false;
                this.lb_last.enabled = false;
            }
            this.rpt_sword_list.datasource = pds;
            this.rpt_sword_list.databind();
            conn.close();
        }

        #region web 窗体设计器生成的代码
        override protected void oninit(eventargs e)
        {
            //
            // codegen: 该调用是 asp.net web 窗体设计器所必需的。
            //
            initializecomponent();
            base.oninit(e);
        }

        /// <summary>
        /// 设计器支持所需的方法 - 不要使用代码编辑器修改
        /// 此方法的内容。
        /// </summary>
        private void initializecomponent()
        {    
            this.lb_frist.click += new system.eventhandler(this.lb_frist_click);
            this.lb_p.click += new system.eventhandler(this.lb_p_click);
            this.lb_n.click += new system.eventhandler(this.lb_n_click);
            this.lb_last.click += new system.eventhandler(this.lb_last_click);
            this.load += new system.eventhandler(this.page_load);

        }
        #endregion

        private void lb_frist_click(object sender, system.eventargs e)
        {
            this.lbl_current_page.text = "1";
            this.db_bind();
        }

        private void lb_p_click(object sender, system.eventargs e)
        {
            this.lbl_current_page.text = convert.tostring(convert.toint32(this.lbl_current_page.text)-1);
            this.db_bind();
        }

        private void lb_n_click(object sender, system.eventargs e)
        {
            this.lbl_current_page.text = convert.tostring(convert.toint32(this.lbl_current_page.text)+1);
            this.db_bind();
        }

        private void lb_last_click(object sender, system.eventargs e)
        {
            this.lbl_current_page.text = this.lbl_total_page.text;
            this.db_bind();
        }
    }
}