分页字符串

/// <summary>
        /// 获取分页字符串(通用)
        /// </summary>
        /// <param name="page">当前页码</param>
        /// <param name="pageSize">页面大小</param>
        /// <param name="Url">分页链接</param>
        /// <param name="strWhere">查询条件</param>
        /// <param name="tblName">数据表</param>
        ///  <param name="pageType">页面名称(文件夹名字)</param>
        /// <param name="typeId">类别id</param>
        /// <returns></returns>
        public static string GoToPagerPublic(int page, int pageSize, string Url, string strWhere, string tblName, string pageType, int typeId,string keyword)
        {
            if (tblName == null) goto Err;

            DataTable tb = GetDataTable(strWhere, tblName);
            int Count = Convert.ToInt32(tb.Rows[0]["Total"]);  //取得总的记录数

            StringBuilder strHtml = new StringBuilder();
            int prevPage = page - 1;    //上一页
            int nextPage = page + 1;    //下一页
            int startPage;
            int pageCount = (int)Math.Ceiling((double)Count / pageSize);    //总页数
            if (pageCount <= 1)
            {
                return "";
            }

            strHtml.Append("<p class=\"page mar_top\">");
          
            if (prevPage < 1)
            {
                strHtml.Append("<a title=\"首页\" href=\"javasrcipt:void(0)\">首页</a>");
                strHtml.Append("<a title=\"上一页\" href=\"javasrcipt:void(0)\">上一页</a>");
            }
            else
            {
                strHtml.Append("<a title=\"首页\" href=\"" + Base.BasePage.Config.WebURL + ""+pageType+"/Trade.aspx?id=" + typeId + "&page=1&keyword=" + keyword + "\">首页</a>");
                strHtml.Append("<a title=\"上一页\" href=\"" + Base.BasePage.Config.WebURL + "" + pageType + "/Trade.aspx?id=" + typeId + "&page=" + prevPage + "&keyword=" + keyword + "\">上一页</a>");

             }
            if (page % 6 == 0)
            {
                startPage = page - 5;
            }
            else
            {
                startPage = page - page % 6 + 1;
            }
            if (startPage > 6)
            {
                //strHtml.Append(@"<a href='");
                //strHtml.Append(Url);
                //strHtml.Append(startPage - 1 + Base.BasePage.Config.Rewrite);
                //strHtml.Append(@"'>...</a>");
                strHtml.Append("<a href=\"" + Base.BasePage.Config.WebURL + "" + pageType + "/Trade.aspx?id=" + typeId + "&page=" + (startPage - 1) + "&keyword=" + keyword + "\">...</a>");
            }
            for (int i = startPage; i < startPage + 6; i++)
            {
                if (i > pageCount) break;
                if (i == page)
                {
                    strHtml.Append("<span class=\"page1\">" + i + "</span>");
                }
                else
                {
                    strHtml.Append("<a title=\"" + i + "\" href=" + Base.BasePage.Config.WebURL + "" + pageType + "/Trade.aspx?id=" + typeId + "&page=" + i + "&keyword=" + keyword + ">" + i + "</a>");
                }
            }
            //if (pageCount >= startPage + 6) strHtml.Append(@"<span><a href='" + Url + (startPage + 6) + Base.BasePage.Config.Rewrite + "'>...</a></span>");
            if (nextPage > pageCount)
            {
                strHtml.Append("<a title=\"下一页\" href=\"javasrcipt:void(0)\">下一页</a>");
                strHtml.Append("<a title=\"末页\" href=\"javasrcipt:void(0)\">末页</a>");
            }
            else
            {
                strHtml.Append("<a title=\"下一页\" href='" + Base.BasePage.Config.WebURL + "" + pageType + "/Trade.aspx?id=" + typeId + "&page=" + nextPage + "&keyword=" + keyword + "'>下一页</a>");
                strHtml.Append("<a title=\"末页\" href='" + Base.BasePage.Config.WebURL + "" + pageType + "/Trade.aspx?id=" + typeId + "&page=" + pageCount + "&keyword=" + keyword + "'>末页</a>");
            }
            strHtml.Append("共" + pageCount + "页 到第");
            strHtml.Append("<input name=\"\" type=\"text\" class=\"input2\" style=\"width:30px;\" />页");
            strHtml.Append("<input name=\"\" type=\"button\" class=\"soso\" value=\"确定\" />");
            #region 修改前2011.4.27
            //strHtml.Append("当前页:<font class=\"f_c00\">" + page + "</font>/" + pageCount + "页 共<font class=\"f_c00\">" + Count + "</font>条");
            //strHtml.Append(" 转到<SELECT id=select1 LANGUAGE=javascript onchange=\"location.href=this.value\">");
            //strHtml.Append("<OPTION>请选择</OPTION>");
            //for (int i = 1; i <= pageCount; i++)
            //{
            //    strHtml.Append("<OPTION value=\"" + Base.BasePage.Config.WebURL + "News/Trade.aspx?id=" + typeId + "&page=" + i + "&keyword=" + keyword + "\">第" + i + "页</OPTION>");
            //}
            //strHtml.Append("</SELECT>");
            #endregion
            strHtml.Append("</p>");

            return strHtml.ToString();

        Err:
            return "缺少数据表或视图";
        }

posted @ 2011-04-27 13:42  红鲤鱼与驴与绿鲤鱼  阅读(359)  评论(1编辑  收藏  举报