repeater分页 内容显示

所属分类: 网络编程 / ASP.NET 阅读数: 1220
收藏 0 赞 0 分享
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();
        }
    }
}
更多精彩内容其他人还在看

ASP.Net 之Datalist删除功能详解附代码

ASP.Net 之Datalist删除功能详解附代码,需要的朋友可以参考一下
收藏 0 赞 0 分享

ASP.NET(C#)验证数字的两种方法

ASP.NET(C#)验证数字的两种方法,需要的朋友可以参考一下
收藏 0 赞 0 分享

此页的状态信息无效,可能已损坏 的处理办法及原因分析

此页的状态信息无效,可能已损坏 的处理办法及原因分析,需要的朋友可以参考一下
收藏 0 赞 0 分享

MultiLine 换行后实现读取不换行的具体思路

输入内容中有换行,保存到数据库,直接查看感觉没有换行,但查询结果“以文本格式显示结果”你就会发现 其实是有换行的,下面与大家分享下具体的解决方法
收藏 0 赞 0 分享

swfupload ajax无刷新上传图片实例代码

在这里上传图片就需要用到ajax无刷新上传图片,这里面包含的东西不是一点半点。这里用到的是一个插件swfupload实现无刷新上传图片,感兴趣的朋友可以参考下哈
收藏 0 赞 0 分享

静态gb2312编码在项目传值出现中文乱码现象

参考的美工静态页面是gb2312格式的,当此编码拿到项目中后,utf-8编码的系统,加载页面时,会出现样式问题,比如不能正常居中等
收藏 0 赞 0 分享

System.Timers.Timer定时执行程序示例代码

如果是某个逻辑功能的定时,可以将code放到逻辑功能的类的静态构造函数中,在该逻辑类第一次执行时,静态构造函数会被调用,则定时自然启动
收藏 0 赞 0 分享

分享下Asp.Net面试题目及答案集合

这篇文章主要是总结asp.net开发人员在面试过程中常遇到的一些问题小结,需要的朋友可以参考下
收藏 0 赞 0 分享

给自定义Web控件添加事件(前后台代码)

给自定义控件(Web Control)添加事件具体前后台代码如下,感兴趣的朋友可以参考下哈
收藏 0 赞 0 分享

ASP.NET过滤器的应用方法介绍

ASP.NET过滤器的应用方法介绍,需要的朋友可以参考一下
收藏 0 赞 0 分享
查看更多