Repeater自己写了个分页类

在做项目的时候经常要用到分页

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
namespace AspNetPage
{
    /// <summary>
    /// MyAspNetPage 的摘要说明
    /// </summary>
    public class MyAspNetPage
    {
        public  MyAspNetPage()
        {
            //
            // TODO: 在此处添加构造函数逻辑
            //
        }
        //DS,rpt,共几页,
        public static void RptBind(DataSet ds, Repeater rpt, Literal RecordCount, Literal PageCount, Literal Pageindex, HyperLink FirstPage, HyperLink PrevPage, HyperLink NextPage, HyperLink LastPaeg, Literal Literal1)
        {

            try
            {
                PagedDataSource objPage = new PagedDataSource();
                objPage.DataSource = ds.Tables[0].DefaultView;//ds.Tables[0].DefaultView;
                objPage.AllowPaging = true;
                objPage.PageSize = 10;
                int CurPage;
                if (System.Web.HttpContext.Current.Request.QueryString["Page"] != null)
                {
                    CurPage = Convert.ToInt32(System.Web.HttpContext.Current.Request.QueryString["page"]);
                }
                else
                {
                    CurPage = 1;
                }
                objPage.CurrentPageIndex = CurPage - 1;
                rpt.DataSource = objPage;//这里更改控件名称  
                rpt.DataBind();
                RecordCount.Text = objPage.DataSourceCount.ToString();
                PageCount.Text = objPage.PageCount.ToString();
                Pageindex.Text = CurPage.ToString();
                Literal1.Text = PageList(objPage.PageCount, CurPage);

                FirstPage.NavigateUrl = System.Web.HttpContext.Current.Request.CurrentExecutionFilePath + "?page=1";
                PrevPage.NavigateUrl = System.Web.HttpContext.Current.Request.CurrentExecutionFilePath + "?page=" + (CurPage - 1);
                NextPage.NavigateUrl = System.Web.HttpContext.Current.Request.CurrentExecutionFilePath + "?page=" + (CurPage + 1);
                LastPaeg.NavigateUrl = System.Web.HttpContext.Current.Request.CurrentExecutionFilePath + "?page=" + objPage.PageCount.ToString();
                if (CurPage <= 1 && objPage.PageCount <= 1)
                {
                    FirstPage.NavigateUrl = "";
                    PrevPage.NavigateUrl = "";
                    NextPage.NavigateUrl = "";
                    LastPaeg.NavigateUrl = "";
                }
                if (CurPage <= 1 && objPage.PageCount > 1)
                {
                    FirstPage.NavigateUrl = "";
                    PrevPage.NavigateUrl = "";
                }
                if (CurPage >= objPage.PageCount)
                {
                    NextPage.NavigateUrl = "";
                    LastPaeg.NavigateUrl = "";
                }
            }
            catch (Exception error)
            {
                System.Web.HttpContext.Current.Response.Write(error.ToString());
            }
        }
        private static string PageList(int Pagecount, int Pageindex)//private string Jump_List(int Pagecount , int Pageindex , long L_Manage)//带参数的传递  
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("<select id=/"Page_Jump/" name=/"Page_Jump/" onchange=/"window.location='" + System.Web.HttpContext.Current.Request.CurrentExecutionFilePath + "?page='+ this.options[this.selectedIndex].value + '';/">");

            for (int i = 1; i <= Pagecount; i++)
            {
                if (Pageindex == i)
                    sb.Append("<option value='" + i + "' selected>" + i + "</option>");
                else
                    sb.Append("<option value='" + i + "'>" + i + "</option>");
            }
            sb.Append("</select>");
            return sb.ToString();
        }
    }
}
--------------------------------------------------------------------------------------------

上图

阅读更多

扫码向博主提问

厦门德仔

博客专家

非学,无以致疑;非问,无以广识
  • 擅长领域:
  • ERP
  • .NET
  • SQL
  • Ext.Net
  • DevExpress
去开通我的Chat快问
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/david_520042/article/details/5633587
个人分类: .Net Grid/Wbs/Xml
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭
关闭