data list分页功能的实现

 data list分页显示图片功能的实现:
1. 定义静态变量
    private static PhotoTables photos = new PhotoTables(); '存储图片路径列表
    '记录所有页和当前页
     private static Int32 current_pos = 1;
    private static Int32 totalPage;
    private static Int32 currPage;
    private enum pageAct{down,up};
 2.实现翻页函数
    //翻页
    private void pageTurn(Int32 action)
    {
        switch (action)
        {
            case (Int32)pageAct.down:
                {
                    if (currPage == totalPage)
                    {
                        pageTurn((Int32)pageAct.up);
                        return;
                    }
                    else
                    {
                        currPage += 1;
                        current_pos += 36;
                        showPhoto();
                    }
                    break;
                }
            case (Int32)pageAct.up:
                {
                    if (currPage == 1)
                    {
                        //pageTurn(pageAct.up);
                        return;
                    }
                    else
                    {
                        currPage -= 1;
                        current_pos -= 36;
                        showPhoto();
                    }
                    break;
                }
        }
        procPage();
    }

    //计算页数
    private void calPage()
    {
        Int32 rowCount = photos.Count;
        Int32 mod;

        totalPage = rowCount / 36;
        mod = rowCount % 36;
        if (mod > 0) totalPage += 1;
        current_pos = 1;
        currPage = 1;
        procPage();
    }

3.显示当前页图片函数

    //显示当前页图片
    private void showPhoto()
    {
        Int32 i = 1;
        Int32 len = 1;
        PhotoTables ps = new PhotoTables();
        foreach (PhotoTable photo in photos)
        {
            if (i >= current_pos)
            {
                len = i - current_pos;
                ps.Add(photo);
                if (len >= 35)
                {
                    dlPhoto.DataSource = ps;
                    dlPhoto.DataBind();
                    //current_pos += len;
                   
                    return;
                }
            }
            i += 1;
        }
        dlPhoto.DataSource = ps;
        dlPhoto.DataBind();
        //current_pos += len;
       
    }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值