文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>GridView、DataList等数据源控件的手写分页代码

GridView、DataList等数据源控件的手写分页代码

时间:2010-10-15  来源:_木子

public void getMessageList()
    {
        DataSet ds = myData.getDataSet("server=.;database=‘数据库名称’;uid=数据库服务器登录账号; pwd=数据库服务器登录密码;", CommandType.Text, "select * from [lyInfo] order by [lyDate] desc");
        int currentpage = Convert.ToInt32(this.labCurrentPage.Text);
        PagedDataSource ps = new PagedDataSource();
        ps.AllowPaging = true;
        ps.PageSize = 5;
        ps.CurrentPageIndex = currentpage - 1;
        ps.DataSource = ds.Tables[0].DefaultView;
        this.labTotalPage.Text = ps.PageCount.ToString();
        this.dl_Message.DataSource = ps;
        this.dl_Message.DataBind();

        this.lkb_shouye.Enabled = true;
        this.lkb_shangyiye.Enabled = true;
        this.lkb_weiye.Enabled = true;
        this.lkb_xiayiye.Enabled = true;
        if (ps.IsFirstPage)
        {
            this.lkb_shouye.Enabled = false;
            this.lkb_shangyiye.Enabled = false;
        }
        if (ps.IsLastPage)
        {
            this.lkb_weiye.Enabled = false;
            this.lkb_xiayiye.Enabled = false;
        }
    }

//首页
    protected void lkb_shouye_Click(object sender, EventArgs e)
    {
        this.labCurrentPage.Text = "1";
        this.lkb_shouye.Enabled = false;
        this.lkb_shangyiye.Enabled = false;
        getMessageList();
    }

//上一页
    protected void lkb_shangyiye_Click(object sender, EventArgs e)
    {
        if (this.labCurrentPage.Text == "1")
        {
            this.RegisterStartupScript("alert", "<scrip>alter('已经是第一页')</script>");
            getMessageList();
        }
        this.labCurrentPage.Text = (Convert.ToInt32(this.labCurrentPage.Text) - 1).ToString();
        getMessageList();
    }

//下一页
    protected void lkb_xiayiye_Click(object sender, EventArgs e)
    {
        this.labCurrentPage.Text = (Convert.ToInt32(this.labCurrentPage.Text) + 1).ToString();
        getMessageList();
    }

//尾页
    protected void lkb_weiye_Click(object sender, EventArgs e)
    {
        this.labCurrentPage.Text = this.labTotalPage.Text; ;
        this.lkb_weiye.Enabled = false;
        this.lkb_xiayiye.Enabled = false;
        getMessageList();
    }

相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载