原创

Repeater自己写了个分页类

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://david.blog.csdn.net/article/details/5633587

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

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/" οnchange=/"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();
        }
    }
}
--------------------------------------------------------------------------------------------

上图

文章最后发布于: 2010-05-29 20:34:00
展开阅读全文
0 个人打赏
私信求帮助

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

©️2019 CSDN 皮肤主题: 鲸 设计师: meimeiellie

分享到微信朋友圈

×

扫一扫,手机浏览