DAL层
 public DataSet GetPage(int pageindex, int cid)
        {
            return Common.GetPage("Photo", "ID", 25, pageindex, 0, 1, "Passed=1 AND CID=" + cid);
        }Common公共类
 public static DataSet GetPage(string tablename, string fldname, int pagesize, int pageindex, int iscount, int ordertype, string strwhere)
        {
            DataSet ds = SqlHelper.ExecuteDataset(SqlHelper.ConnectionString, CommandType.StoredProcedure, "GetPage", new SqlParameter[]{
                new SqlParameter("@tblName",tablename),
                new SqlParameter("@fldName",fldname),
                new SqlParameter("@PageSize",pagesize),
                new SqlParameter("@PageIndex",pageindex),
                new SqlParameter("@IsCount",iscount),
                new SqlParameter("@OrderType",ordertype),
                new SqlParameter("@strWhere",strwhere)
            });
            return ds;
        }UI层
BLL.Photo_BLL photo_bll = new BLL.Photo_BLL();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (!string.IsNullOrEmpty(Request.QueryString["CID"]))
                {
                    int cid = Convert.ToInt32(Request.QueryString["CID"]);
                    lb_Allpage.Text = Count().ToString();
                    if (!string.IsNullOrEmpty(Request.QueryString["Page"]))
                    {
                        int curpage = Convert.ToInt32(Request.QueryString["Page"]);
                        lb_CurrentPage.Text = curpage.ToString();
                        photo_bll.ShowNumber(curpage, Count(), Num, "/Photo/listnews.aspx?CID=" + cid + "&Page=");
                        Bind(curpage, Count(),cid);
                    }
                    else
                    {
                        lb_CurrentPage.Text = "1";
                        photo_bll.ShowNumber(1, Count(), Num, "/Photo/listnews.aspx?CID=" + cid + "&Page=");
                        Bind( 1, Count(),cid);
                    }
                }
            }
        }
        public int Count()
        {
            int cid = Convert.ToInt32(Request.QueryString["CID"]);
            return photo_bll.GetCount(cid);
        }
        public void Bind(int pageindex,int countpage,int cid)
        {
            Re_Bind.DataSource = photo_bll.GetPage(pageindex, cid);
            Re_Bind.DataBind();
            if (pageindex <= 1)
            {
                Hy_pre.Enabled = false;
                Hy_first.Enabled = false;
                Hy_next.NavigateUrl = "/Photo/listnews.aspx?CID=" + cid + "&Page=" + (pageindex + 1).ToString();
                Hy_end.NavigateUrl = "/Photo/listnews.aspx?CID=" + cid + "&Page=" + countpage.ToString();
            }
            else
            {
                Hy_first.NavigateUrl = "/Photo/listnews.aspx?CID=" + cid + "&Page=1";
                Hy_pre.NavigateUrl = "/Photo/listnews.aspx?CID=" + cid + "&Page=" + (pageindex - 1).ToString();
            }
            if (pageindex > countpage - 1)
            {
                Hy_first.NavigateUrl = "/Photo/listnews.aspx?CID=" + cid + "&Page=1";
                Hy_pre.NavigateUrl = "/Photo/listnews.aspx?CID=" + cid + "&Page=" + (pageindex - 1).ToString();
                Hy_next.Enabled = false;
                Hy_end.Enabled = false;
            }
            else
            {
                Hy_next.NavigateUrl = "/Photo/listnews.aspx?CID=" + cid + "&Page=" + (pageindex + 1).ToString();
                Hy_end.NavigateUrl = "/Photo/listnews.aspx?CID=" + cid + "&Page=" + countpage.ToString();
            }
        }经过昨天各位大侠的指点,学到了点东西
希望各位大侠在指点下有什么不对的地方,该改进的地方

解决方案 »

  1.   


    BLL层
    DAL.Photo_DAL photo_dal;
    public Photo_BLL()
    {
         photo_dal = new DAL.Photo_DAL();
    }
    public DataSet GetPage(int pageindex,int cid)
    {
         return photo_dal.GetPage(pageindex, cid);
    }
    希望各位大侠指点迷津!
      

  2.   

     public static DataSet GetPage(string tablename, string fldname, int pagesize, int pageindex, int iscount, int ordertype, string strwhere)
    为何要是静态的?而且还是public?
      

  3.   

    You should add some code for error handling and logging. And also check if data source is null.
      

  4.   

    因为经常要用到分页,就用了static。public这个没去注意额
      

  5.   

    分页看看aspnetpager结合三层的实现方法