datalist数字分页代码

来源:互联网 发布:淘宝咖啡店推荐 编辑:程序博客网 时间:2024/06/03 01:56

public void PageNum()
    {
        string sql = "select *from Calls";
        DataSet ds = DBO.ExecuteDataSet(CommandType.Text, sql, null);
        for (i = 0; i < ds.Tables[0].Rows.Count / 5; i++)
        {
            divPageNum.InnerHtml += "<a href='Default4.aspx?p=" + (i + 1).ToString() + "'>" + (i + 1).ToString() + "</a>&nbsp;";
        }


        PagedDataSource objPds = new PagedDataSource();
        objPds.DataSource = ds.Tables[0].DefaultView;
        objPds.AllowPaging = true;
        objPds.PageSize = 5;
        if (Request.QueryString["p"] != null)
            CurrentPage = Convert.ToInt32(Request.QueryString["p"]);
        else
            CurrentPage = 1;

        objPds.CurrentPageIndex = CurrentPage - 1;

        this.DataList1.DataSource = objPds;
        DataList1.DataBind();
    }

原创粉丝点击