NET DataList 分页源码 (转)

原创 2007年09月23日 08:03:00
 private const int PAGECOUNT = 9;
    private static int nPhotoCount = 0;
    private int nPhotoAllPageCount = 0;
    private int nPhotoCurrentPage = 0;

    protected void Page_Load(object sender, EventArgs e)
    {

        if (ViewState["PhotoCurrentPage"] != null)
        {
            nPhotoCurrentPage = Int32.Parse(ViewState["PhotoCurrentPage"].ToString());
        }
        if (!Page.IsPostBack)
        {
            BindPhotoData();
            //重新绑定当前的页码   
            Label3.Text = (nPhotoCurrentPage + 1).ToString() + " ";
        }
    }
    private void BindPhotoData()
    {
        SqlDataAdapter ad = new SqlDataAdapter("select * from sysobjects","server=.;database=master;uid=sa;pwd=;");
        DataSet set = new DataSet();
        ad.Fill(set);
        nPhotoCount = set.Tables[0].Rows.Count;
        nPhotoAllPageCount = nPhotoCount / PAGECOUNT;
        if (nPhotoAllPageCount * PAGECOUNT < nPhotoCount)
        {
            nPhotoAllPageCount++;
        }
        //照片的总数量和总页数
        Label1.Text = nPhotoAllPageCount.ToString() + " ";
        Label2.Text = nPhotoCount.ToString() + " ";
        DataSet ds =GetPhotoes(nPhotoCurrentPage * PAGECOUNT, PAGECOUNT);
        DataList1.DataSource = ds;
        DataList1.DataBind();
    }
    public DataSet GetPhotoes(int a,int b)
    {
        SqlDataAdapter ad = new SqlDataAdapter("select * from sysobjects", "server=.;database=master;uid=sa;pwd=;");
        DataSet set = new DataSet();
        ad.Fill(set, a, b, "sysobjects");
        return set;

    }
     private void Page_Click(object sender, System.EventArgs e)
    {
        String commangArg = ((LinkButton)sender).CommandArgument;
        switch (commangArg)
        {
            case "First":
                {
                    nPhotoCurrentPage = 0;
                    break;
                }
            case "Prev":
                {
                    nPhotoCurrentPage = (int)Math.Max(0, nPhotoCurrentPage - 1);
                    break;
                }
            case "Next":
                {
                    nPhotoCurrentPage = (int)Math.Min(nPhotoCount - 1, nPhotoCurrentPage + 1);
                    break;
                }
            case "Last":
                {
                    nPhotoCurrentPage = nPhotoCount - 1;
                    break;
                }
            default:
                {
                    break;
                }
        }
        ViewState["PhotoCurrentPage"] = nPhotoCurrentPage.ToString();
        BindPhotoData(); 
        Label3.Text = (nPhotoCurrentPage + 1).ToString() + " ";
    }

 
版权声明:本文为博主原创文章,未经博主允许不得转载。

相关文章推荐

DataList 分页源码 txt版

asp.net DataList控件分页代码

asp.net之DataList的使用方法,及分页(存储过程创建),编辑,更新,删除

using System; using System.Collections.Generic; using System.Linq; using System.Web; using Syste...

asp.net中Datalist使用数字分页的实现方法

http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> http://www.w3.org/1999/xhtml"> 无标...

asp.net用datalist进行分页

前台代码: 这个是前台代码:必须要先设计号界面 ...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)